Java OCA OCP Practice Question 1700

Question

Which one of the following class declarations is a valid declaration of a class that cannot be instantiated?

Select the one correct answer.

  • (a) class Main { abstract void m(); }
  • (b) abstract class Main { void m(); }
  • (c) abstract class Main { void m() {}; }
  • (d) abstract Main { abstract void m(); }
  • (e) static class Main { abstract m(); }


(c)

Note

Any normal class can be declared abstract.

A class cannot be instantiated if the class is declared abstract.

The declaration of an abstract method cannot provide an implementation.

The declaration of a non-abstract method must provide an implementation.

If any method in a class is declared abstract, then the class must be declared abstract, so (a) is invalid.

The declaration in (b) is not valid, since it omits the keyword abstract in the method declaration.

The declaration in (d) is not valid, since it omits the keyword class.




PreviousNext

Related