class Dad
{
protected static String me = "dad";
public void printMe()
{
System.out.println(me);
}
}
class Son extends Dad
{
protected static String me = "son";
}
public void doIt()
{
new Son().printMe();
}
When you execute this code, "dad" is printed out. Can't we print out the son?
inheritance java override
I can do it. If you do not define me in the lower class, me in the upper class is automatically overridden.
© 2024 OneMinuteCode. All rights reserved.