Java OCA OCP Practice Question 1431

Question

Which one of the following class definitions is/are a legal definition of a class that cannot be instantiated?

class Main{ //from w  ww . j  a  v a  2  s .c o  m
   abstract void honk ();  // (1) 
} 

abstract class Main{ 
   void honk ();   // (2) 
} 

abstract class Main{ 
   void honk (){};   // (3) 
} 

abstract class Main{ 
   abstract void honk (){}   // (4) 
} 

abstract class Main{ 
   abstract void honk ();   // (5) 
} 

Select 2 options

  • A. 1
  • B. 2
  • C. 3
  • D. 4 E. 5


Correct Options are  : C E

Note

A class is uninstantiable if the class is declared abstract.

If a method has been declared as abstract, it cannot provide an implementation.

A method body even if empty and the class containing that method must be declared abstract.

If a method is not declared abstract, it must provide a method body.

If any method in a class is declared abstract, then the whole class must be declared abstract.




PreviousNext

Related