zoukankan      html  css  js  c++  java
  • 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("好好学习,高薪就业");
        }
    }
  • 相关阅读:
    洛谷 P2979 [USACO10JAN]奶酪塔Cheese Towers
    celery -2
    【express】
    ↗☻【HTML5秘籍 #BOOK#】第8章 使用CSS3
    -_-#【Dom Ready / Dom Load】
    【jQuery】
    ♫【Avalon】
    【兼容】IE下PNG色差
    ↗☻【HTML5秘籍 #BOOK#】第4章 Web表单
    洛谷—— P1328 生活大爆炸版石头剪刀布
  • 原文地址:https://www.cnblogs.com/longesang/p/11225756.html
Copyright © 2011-2022 走看看