Java OCA OCP Practice Question 2700

Question

Consider the following declaration and choose a correct option:

abstract class abstClass{
        public void print1();
        final void print2(){};
        public abstract final void print3();
        public abstract static void print4();
}
  • a) Methods print1(), print2(), and print3() will not compile.
  • b) Methods print1(), print3(), and print4() will not compile.
  • c) Methods print3() and print4() will not compile.
  • d) Methods print1() and print3() will not compile.


b)

Note

The method print2() is correct since it defines a method and declares it final, which is acceptable.

The method print1() is incorrect since either a method has a body or it needs to be declared as abstract in an abstract class.

Method print3() is not correct since a method cannot be abstract and final at the same time.

Similarly, print4() is also not correct since a method cannot be static and abstract at the same time.




PreviousNext

Related