One.java
public class One {
private void run() {
System.out.println("one");
}
public void start() {
this.run();
}
}
Two.java
public class Two extends One {
public void run() {
System.out.println("two");
}
}
Main.java
public class Main {
public static void main(String[] args) {
Two t = new Two();
t.start();
}
}
Output: one
But if I declare the run
method public
in the One
class I get "two" as output.
It is pretty unpredictable, how does this work?