java - 关于Object匿名内部类的一些问题
PHP中文网
PHP中文网 2017-04-18 10:54:04
0
2
472
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();
    }
}

这个代码没有了输入这是怎么回事呢??

PHP中文网
PHP中文网

认证0级讲师

reply all(2)
阿神

Did you print the first one? ? ?

刘奇

The second piece of code is missing System.out.println, how can there be output.

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!