Java OCA OCP Practice Question 1022

Question

Given:

//Insert code here   

   public abstract void draw (); 
} 

//Insert code here 
   public void draw (){  System.out.println ("in draw ...");  } 
} 

Which of the following lines of code can be used to complete the above code?

Select 2 options

A. class Shape  { 
   and /*from w  ww.  j a v  a2  s.  c  o m*/
   class Circle  extends Shape  { 

B. public class Shape  { 
   and 
   class Circle  extends Shape  { 

C. abstract Shape  { 
   and 
   public class Circle  extends Shape  { 

D. public abstract class Shape  { 
   and 
   class Circle  extends Shape  { 

E. public abstract class Shape  { 
   and 
   class Circle  implements Shape  { 

F. public interface Shape  { 
   and 
   class Circle  implements Shape  { 


Correct Options are  : D F

Note

A. is wrong. Since there is an abstract method in the first class, the class must be declared abstract.

C. is wrong. class keyword is missing from the first declaration.

E. is wrong. You can only implement an interface not a class. So Circle implements shape is wrong.

F. is correct. By default all the methods of an interface are public and abstract so there is no need to explicitly specify the "abstract" keyword for the draw() method if you make Shape an interface. But it is not wrong to do so.




PreviousNext

Related