概念
代码
package lesson.l10_oop;/*** Illustration** @author DengQing* @version 1.0* @datetime 2022/7/1 13:39* @function 匿名对象*/
public class Anonymous {public static void main(String[] args) {
// 用法1new Teacher().say("dq");new Teacher().walk("西昌");
// 用法2Anonymous anonymous = new Anonymous();anonymous.run(new Teacher());}public void run(Teacher teacher) {teacher.say("dq");teacher.walk("西昌");}
}class Teacher {public void say(String name) {System.out.println(name + "今天做得很好!");}public void walk(String address) {System.out.println("今天去" + address);}
}