注意:

1、只能使用一次,所以一般不用(匿名对象,每次都会创建新的对象)

2、可以做为参数或返回值

例子

Person.java

package cn.wt.day07.Demon01A;

public class Person {
    // 成员变量
    String name;
    // 成员方法
    public void isIntro(){
        System.out.println("大家好,我叫" + name);
    }
}

Demon01Test.java

package cn.wt.day07.Demon01A;

public class Demon01Test {
    public static void main(String[] args) {
        // 下面两行代码没有联系,匿名对象每一次都是创建新的对象
        new Person().name = "tom";
        new Person().isIntro();
    }
}

相关文章:

  • 2021-11-11
  • 2021-09-28
  • 2021-05-31
  • 2021-10-16
  • 2021-08-27
  • 2022-12-23
  • 2021-12-14
猜你喜欢
  • 2021-04-04
  • 2021-07-25
  • 2021-08-29
  • 2022-01-30
  • 2022-12-23
  • 2021-06-05
相关资源
相似解决方案