Java OCA OCP Practice Question 2077

Question

Consider the following program and predict the behavior of this program:.

class Base {/*from   ww w .  j  a v a 2s  .c o  m*/
     public void print() {
             System.out.println("Base:print");
     }
}

abstract class Main extends Base { //#1
     public static void main(String[] args) {
             Base obj = new Base();
             obj.print(); //#2
     }
}
  • A. Compiler error "an abstract class cannot extend from a concrete class" at statement marked with comment #1
  • B. Compiler error "cannot resolve call to print method" at statement marked with comment #2
  • C. the program prints the following: Base:print
  • D. the program will throw a runtime exception of AbstractClassInstantiationException


C.

Note

An abstract class can extend a concrete class.

An abstract class can have static methods.

You don't need to create an object of a class to invoke a static method in that class.

You can invoke the main() method defined in an abstract class.




PreviousNext

Related