Java OCA OCP Practice Question 2607

Question

Which of the following can be inserted to override the superclass method? (Choose all that apply.)

public class Main { 
   public void walk() {} 
   class InnerClass extends Main { 
      // INSERT CODE HERE 
   } 
} 
  • A. public void walk() {}
  • B. public void Walk() {}
  • C. public final void walk() {}
  • D. public static void walk() {}
  • E. public void walk() throws Exception {}
  • F. public void walk(boolean fall) {}


A, C.

Note

An override must have the same method signature.

A and C both do.

F is an overload because it has a different parameter list.

E does not compile because it throws a checked exception not declared in the superclass.

D compiles but is not an override because it is static.

B has a different method name, so it is not even an overload.




PreviousNext

Related