Why does the below code print "Main"?
public class Main
{
public static void method()
{
System.out.println("Main");
}
public static void main(String[] args)
{
Main m = new SubMain();
m.method();
}
}
class SubMain extends Main
{
public static void method()
{
System.out.println("SubMain");
}
}
At runtime, m is pointing to an instance of Submain, so it should conceptually print "SubMain".
Main m = null;and then call the method, the expression before the dot is not used at all.