Java OCA OCP Practice Question 1889

Question

What is the correct declaration for an abstract method 'add' accessible to any class, takes no arguments and returns nothing?.

Use only one space between words

Select 1 option

  • A. public void add ();
  • B. abstract add ();
  • C. abstract null add ();
  • D. abstract public void add (){ }
  • E. abstract public void add () throws Exception;


Correct Option is  : E

Note

For A.

An abstract method must have the abstract keyword and must not have a method body i.e. { }.

For B.

A method that is not supposed to return anything must specify void as its return type.

For C.

A method that is not supposed to return anything must specify void as its return type.

null is not a type, though it is a valid return value for any type.

For D.

It is invalid because has a method body i.e. { }.




PreviousNext

Related