• 23.2 匿名对象


    package com.itheima_01;
    /*
    * 匿名对象:没有名字的对象
    * 匿名对象的应用场景:
    * 当方法只调用一次的时候可以使用匿名对象
    * 可以当作参数进行传递,但是无法在传参之前做其他的事情
    *
    * 注意:匿名对象可以调用成员变量并赋值,但是赋值并没有意义
    *
    */

    package com.itheima_01;
    /*
     * 匿名对象:没有名字的对象
     * 匿名对象的应用场景:
     *         当方法只调用一次的时候可以使用匿名对象
     *         可以当作参数进行传递,但是无法在传参之前做其他的事情
     *     
     * 注意:匿名对象可以调用成员变量并赋值,但是赋值并没有意义
     *             
     */
    public class AnonymousObejctDemo {
        public static void main(String[] args) {
            //Student s = new Student();
            //s.study();
            //s.study();
            //s.study();
            
            //new Student();//匿名对象,没有变量引用的对象
            //new Student().study();
            //new Student().study();
            //new Student().study();
            
            //new Student().age = 18;
            //System.out.println(new Student().age);
            
            
            //Student s = new Student();
            //s.age = 18;
            //s.name = "张三";
            //method(s);
            
            method(new Student());
            
        }
        
        public static void method(Student s) {
            
        }
    
            
    }
    
    
    class Student {
        String name;
        int age;
        
        public void study() {
            System.out.println("好好学习,高薪就业");
        }
    }
  • 相关阅读:
    HDU 1850 Being a Good Boy in Spring Festival
    UESTC 1080 空心矩阵
    HDU 2491 Priest John's Busiest Day
    UVALive 6181
    ZOJ 2674 Strange Limit
    UVA 12532 Interval Product
    UESTC 1237 质因子分解
    UESTC 1014 Shot
    xe5 android listbox的 TMetropolisUIListBoxItem
    xe5 android tts(Text To Speech)
  • 原文地址:https://www.cnblogs.com/longesang/p/11225756.html
Copyright © 2020-2023  润新知