1-匿名对象

匿名对象就是没有名字的对象,如果程序中只是用一次该对象,就可以使用匿名对象的方式。

 1 package com.example;
 2 
 3 /**
 4  * Created by Y on 16/4/13.
 5  */
 6 public class Person {
 7     public void tell(){
 8         System.out.println("hello");
 9     }
10 }
Person
1 package com.example;
2 
3 public class MyClass {
4     public static void main(String[] args){
5         //匿名类是在对象只被使用一次时使用
6         new Person().tell();
7     }
8 }
MyClass

 

posted @ 2017-01-13 10:43  894316728  阅读(97)  评论(0编辑  收藏  举报