Q.36.
class BaseClass
{
static void sayHello()
{
System.out.println("Base");
}
}
public class SubClass extends BaseClass
{
static void sayHello()
{
System.out.println("Sub");
}
public static void main(
String args[])
{
BaseClass bc = new SubClass();
bc.sayHello();
}
}
a)Does'nt compile as you cannot override static methods.
b)Compiles but fails at run-time.
c)prints output : "Base"
d)prints output : "Sub"
The answer is (c).
Using the subclass object,the overridden static method should be invoked .Why is the overridding method of the super class executed ?