Java OCA OCP Practice Question 124

Question

Given:

public abstract interface Action { 
      public void doAction(String s); 
} 

Which is a correct class?

Choose all that apply.

A.   public abstract class Task implements Action { 
            public abstract void doAction(String s) { } 
     } //from   w  w  w  .jav  a2s.  c  om

B.   public abstract class Task implements Action { } 

C.   public class Task extends Action { 
            public void doAction(Integer i) { } 
     } 

D.   public class Task implements Action { 
            public void doAction(Integer i) { } 
     } 

E.   public class Task implements Action { 
            public void doAction(String i) { } 
            public void doAction(Integer s) { } 

     } 


B and E are correct.

Note

B is correct because an abstract class need not implement any or all of an interface's methods.

E is correct because the class implements the interface method and additionally overloads the doAction() method.

A, C, and D are incorrect.

A is incorrect because abstract methods have no body.

C is incorrect because classes implement interfaces; they don't extend them.

D is incorrect because overloading a method is not implementing it.




PreviousNext

Related