class Demo1
{
public void fun()
{
System.out.println(new Object(){
int age = 23;
String name = "李四";
public String toString()
{
return name+","+age;
}
});
}
}
class Demonmnbl2
{
public static void main(String[] args)
{
Demo1 de = new Demo1();
de.fun();
}
}
這個Object的匿名內部類有輸出!
同理下麵的代碼
class Demo1
{
public void fun()
{
new Object()
{ String name1 = "搜索";
public String toString()
{
return name1+",";
}
}
.toString();
}
}
class Demonmnbl2
{
public static void main(String[] args)
{
Demo1 de = new Demo1();
de.fun();
}
}
這個代碼沒有了輸入這是怎麼回事呢??