I have created a very simple program to test which method will be called when that method will be called through inheritance.
Class boo extends foo.
Using boo object, a method from foo class showMe is called. showMe method in foo class calls a method showText to show the text on the screen.
boo class overrides the showText method and show a different text.
My prediction was that the method in foo class will be called instead of its overridden version in boo class. I was wrong and the method in boo class was called. Can someone please explain me how that happened. Also, I want to know how to call the method in the foo class even if I have a overridden method in boo class.
boo class
public class boo extends foo
{
public static void main(String[] args)
{
boo main = new boo();
main.showMe();
}
@Override
public void showText()
{
System.out.println("Bruhhh!!!");
}
}
foo class
public class foo
{
protected void showMe()
{
showText();
}
public void showText()
{
System.out.println("Bruhhh Part 2!!!");
}
}