I am trying to understand the relation b/w parent and child function calling mechanism, but not got this one
class Parent {
Parent() {
greeting();//as we are not calling this on any object, by default it has Parent's greeting method
}
void greeting() {
System.out.println("Greeting Parent");
}
}
public class SuperConstructor extends Parent {
public SuperConstructor() {
//super(); //i know this
greeting();
}
void greeting() {
System.out.println("Greeting Child");
}
public static void main(String[] args) {
new SuperConstructor();
}
}
OUTPUT:
Greeting Child, why ? how things work here ?
Greeting Child
OUTPUT (I expected)
Greeting Parent (reason: as the method is there in Parent class)
Greeting Child