Java OCA OCP Practice Question 1451

Question

Consider the following code:

public abstract class Main{ 
    public abstract void m1 (); 
    public abstract void m2 (){ 
        System.out.println ("hello"); 
    } 
} 

Which of the following corrections can be applied to the above code (independently) so that it compiles without any error?

Select 2 options

  • A. Replace the method body of m2() with a;
  • B. Replace the ; at the end of m1() with a method body.
  • C. Remove abstract from m2().
  • D. Remove abstract from the class declaration.


Correct Options are  : A C

Note

A method that has a body cannot be abstract.

In other words, an abstract method cannot have a body.

So either remove the method body (as in m1()) or remove abstract keyword.




PreviousNext

Related