/** * Created by xabcd on 2019/2/16. */ public class java_nimingduixiang { private String name = "张三"; private int age = 25; public String talk() { return "我是:"+name +",今年:"+age+"岁"; } }
/** * Created by xabcd on 2019/2/16. */ public class test_nimingduixiang { public static void main(String[] args) { System.out.println(new java_nimingduixiang().talk());//声名匿名对象 //没有赋给任何一个值,所以此对象使用了一次,之后就会被垃圾回收 } }