What is the result of the following code?
1: public abstract class Person { 2: private void walk() { System.out.println("Person is walking"); } 3: public static void main(String[] args) { 4: Person p = new Employee(); 5: p.walk(); 6: } 7: } 8: class Employee extends Person { 9: protected void walk() { System.out.println("Employee is walking"); } 10: }
A.
The code compiles and runs without issue, so C, D, and E are incorrect.
walk() is marked as private in the parent class Person, which means it may only be hidden, not overridden.
With hidden methods, the specific method used depends on where it is referenced.
Since it is referenced within the Person class, the method declared on line 2 was used, and option A is correct.