+ 1

Why the reference of an anonymous class isn't the reference to the class of the instanciated object?

In this implementation: class Machine { public void start() { System.out.println("Starting..."); } } class Program { public static void main(String[ ] args) { Machine m1 = new Machine() { @Override public void start() { System.out.println("Wooooo"); } }; Machine m2 = new Machine(); m2.start(); System.out.println(m2); System.out.println(m1); } } OUT PUT: Starting... Machine@7a81197d Program$1@5ca881b5

29th Dec 2020, 8:10 PM
Dhafer ABDELKADER
Dhafer ABDELKADER - avatar
1 Antwort
+ 1
Theres no object of "Machine m1" instead an anonymous inner object of program was created which copied in the code
30th Dec 2020, 12:03 AM
D_Stark
D_Stark - avatar