您的位置:首页 > 其它

对象

2015-11-24 10:53 169 查看
1:匿名对象

/*参数类型可以为一个类
* 类属于引用类型
*
* 匿名对象:就是没有名字的对象
* 匿名对象的应用场景:
*         A:仅仅调用一次的时候
*         B:使用多次的时候匿名对象不合适
*             匿名对象就是垃圾,可以被垃圾回收站回收
*         C:匿名对象可以作为实际参数来传递
*
* */
class Student{
public void show(){
System.out.println("我爱学习");
}
}
class StudentDemo{
public void method(Student s){
s.show();
}
}
public class NoName {
public static void main(String[] args){
Student s = new Student();
s.show();

StudentDemo sd = new StudentDemo();
sd.method(s);

new Student().show();
new StudentDemo().method(new Student());
}
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: