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();
}
}
这个代码没有了输入这是怎么回事呢??
Did you print the first one? ? ?
The second piece of code is missing
System.out.println
, how can there be output.