class BaseClass{
static void sayHello(){
System.out.println("Hi pal!!!, I am BaseClass");
}
}
public class SubClass extends BaseClass{
static void sayHello(){
System.out.println("Hi pal!!!, I am SubClass");
}
public static void main(
String [] arg){
BaseClass bc = new SubClass();
bc.sayHello();
}
}
when i compile and run i am getting
Hi pal!!!, I am BaseClass
My understanding is that even though bc is reference of BaseClass but the object created is that of SubClass() so the SubClass constructor should be called.
Please advice
Thanks in advance
kareem