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("好好学习,高薪就业");
        }
    }
  • 相关阅读:
    window.onresize绑定事件以及解绑事件
    jqGrid中select带可编辑的
    ROS(机器视觉)
    Python(time模块)
    Python(random模块)
    Python迭代器
    Python生成器
    Python装饰器(函数)
    ROS(URDF机器人建模)
    ROS基础
  • 原文地址:https://www.cnblogs.com/longesang/p/11225756.html
Copyright © 2011-2022 走看看