Can someone explain to me why the output of the following code is "From app class". I cannot wrap my head around it.
public abstract class App
{
private void run()
{
System.out.println("From app class");
}
public static void main(String[] args) {
App object = new OtherClass();
object.run();
}
}
class OtherClass extends App
{
protected void run()
{
System.out.println("From otherclass");
}
}
Result: From app class
And why is it when I change to this line of code, the output is "From otherclass":
public static void main(String[] args) {
OtherClass object = new OtherClass();
object.run();
}