http://docs.oracle.com/javase/tutorial/java/javaOO/anonymousclasses.html
hi,
the output of the above code is
Hello world
Salut Fred
Hola, mundo
I noticed that inside the main class:
(that i substituted with
String[] args as I never seen this "String...args" with dots and not with double squares ) there is a call to the method sayHello(), inside there are three classes. Till this should be fine, I am studying a tutorial on anonymous classes and it is clear. I do not understand why calling from the main myApp.sayhello() the output call the line:
System.out.println("Hello " + name);
I mean this sysout i see as first line in the console it is inside a method called
greetSomeone()
that is called inside another method called
greet()
. The point is: who called this greet method??? the main class call myApp.SayHello() not myApp.SayHello().greet() !!!
please do not read the following if it is already clear, really sorry if I am a bit long.
I am really confused so far I saw this behaviour of when there is a constructor, so that when an object is created and instantiated also without a call.. the compiler immediately execute the orders inside the constructor, but in this case who call the Sysout by mean of greet?
Of course there is an interface, so I guess that this behaviour is related to this interface, but as far as I know an interface is only a method to refer to a characteristic in OO that is not present in the super class, so that as it is not C++ every subclass can inherit one superclass. so that an interface does not execute methods but only establishes a contract that the method inside it MUST to be implemented, but still i do not see any specific call to make the compiler executing greet()--> that executes greetSomeone that executes in the end the sysout.
THANKYOU