此时,匿名对象new phone赋值给了形参phone,在show方法内可以多次调用
匿名对象在java中可以充当return的值
匿名对象只可调用一次
如public class Person
{
public String name ;
public int age ;
public Person (String name , int age )
{this .name = name ;this .age = age ;
}
public void tell () {
System .out .println (“姓名:” + name + “,年龄:” + age );
}
public static void main (String [] args ){
new Person (“张三”, 30 ).tell ();
}
}
Original: https://www.cnblogs.com/liujy2233/p/16754371.html
Author: 平凡的柳先生
Title: 匿名对象
原创文章受到原创版权保护。转载请注明出处:https://www.johngo689.com/617040/
转载文章受原作者版权保护。转载请注明原作者出处!