Java Abstract Class Interview MCQ Questions and Answers

Study and learn Interview MCQ Questions and Answers on Abstract Class in Java. Attend job interviews easily with these Multiple Choice Questions. You can print these Questions in default mode to conduct exams directly. You can download these MCQs in PDF format by Choosing Print Option first and Save as PDF option next using any Web Browser.

Go through Java Theory Notes on Abstract Classes before reading these objective questions.



1) An abstract class in Java can be created using the keyword ____.
A) final
B) interface
C) abstract
D) static
Answer [=]
C
Explanation:

You should precede the keyword "abstract" before the keyword "class".

2) To create an Abstract class, the keyword "class" is also required. State TRUE or FALSE.
A) TRUE
B) FALSE
C) -
D) -
Answer [=]
A
Explanation:

True. You create a class using the keyword CLASS and make it abstract using the keyword ABSTRACT.

abstract class ClassA{ }
3) Can you create an object from an abstract class in Java?
A) Yes
B) No
C) -
D) -
Answer [=]
B
Explanation:

No. You can not instantiate or create an object from an abstract class.

4) Which is the opposite of an Abstract Class?
A) Interface
B) concrete class
C) -
D) -
Answer [=]
B
Explanation:

The Concrete Class is the opposite of an Abstract Class. Concrete class defines all the methods completely as opposed to abstract classes that leave implementation to the developers.

5) Choose a correct implementation of an Abstract class in the below Java code?
A)
abstract class ClassA { }
B)
abstract class ClassB
{
  abstract void method();
}
C)
abstract class ClassC
{
  void method()
  {
    System.out.print("Hello Abstract Class");
  }
}
D) All the above
Answer [=]
D
Explanation:

All the above. An abstract class need not contain a single abstract method also.

6) An abstract class in Java usually contains one or more abstract ____.
A) constructors
B) methods
C) variables
D) None
Answer [=]
B
Explanation:

Developers usually write abstract classes with one or more abstract methods to be implemented after inheriting the class.

7) Does the below Java code with abstract method compile?
class Puppy
{
  abstract void showName();
}
A) NO
B) YES
C) -
D) -
Answer [=]
A
Explanation:

No. An abstract method can be defined only by an abstract class.



8) What is the output of the below Java program with an abstract class?
abstract class Coffee
{
  Coffee()
  {
    System.out.println("Inside Constructor of Coffee..");
  }
}
class ColdCoffee extends Coffee
{
  ColdCoffee()
  {
    System.out.println("Inside Constructor of ColdCoffee..");
  }
}
public class AbstractClassTesting
{
  public static void main(String[] args)
  {
    ColdCoffee cf = new ColdCoffee();
  }
}
A) Compiler error
B)
Inside Constructor of Coffee..
Inside Constructor of ColdCoffee..
C)
Inside Constructor of ColdCoffee..
D)
Inside Constructor of Coffee..
Answer [=]
B
Explanation:

An abstract class can contain constructors. The order of invoking of constructors is from the Superclass to Subclass.

9) What is the output of the below Java program with an abstract class?
final abstract class Bell
{  }
class DoorBell extends Bell
{
  DoorBell()
  {
    System.out.println("DoorBell ringing..");
  }
}
public class AbstractClassTesting2
{
  public static void main(String[] args)
  {
    Bell bell = new DoorBell();
  }
}
A) DoorBell ringing..
B) No output
C) Compiler error
D) None of the above
Answer [=]
C
Explanation:

You can not use the keyword FINAL before an abstract class. The classes declared with the "final" keyword can not be subclassed or inherited. So, the FINAL keyword is banned for use with an abstract class. So, the compiler throws an error.

10) What is the output of the below Java program with an abstract class?
abstract class MathLibrary
{
  static final float PI = 3.1415f;
}

public class AbstractClassTesting3
{
  public static void main(String[] args)
  {
    System.out.println(MathLibrary.PI);
  }
}
A) No output
B) Compiler error
C) 3.1415
D) None of the above
Answer [=]
C
Explanation:

The output will be 3.1415. You can define and use a static final variable inside an abstract class. A static final variable is nothing but a constant. It is common to access a static variable with a DOT operator preceded by the Class Name.

11) What is the output of the below Java program with multiple abstract classes?
abstract class Editor
{
  abstract void show();
}

abstract class Author extends Editor
{
  abstract void print();
}

class Office extends Author
{
  void show()
  {
    System.out.println("Editor method");
  }
  void print()
  {
    System.out.println("Author method");
  }
}

public class AbstractClassTesting4
{
  public static void main(String[] args)
  {
    Editor ed = new Office();
    ed.show();

    Author au = new Office();
    au.print();	
  }
}
A)
Editor method
Editor method
B)
Author method
Author method
C)
Editor method
Author method
D) Compiler error
Answer [=]
C
Explanation:

An abstract class can inherit from another abstract class. The final concrete class inheriting the last abstract in the chain should implement all the abstract methods above it.

12) An object of multi-level inherited abstract class can not be created in memory? State TRUE or FALSE.
A) TRUE
B) FALSE
C) -
D) -
Answer [=]
A
Explanation:

True. You can not create objects out of an abstract class whether it is single level or multilevel.

13) An abstract class with 100% abstract methods is equivalent to ______.
A) Concrete class
B) Virtual Class
C) Interface
D) All the above
Answer [=]
C
Explanation:

An interface contains only abstract methods. So it is comparable to a 100% abstract class.

14) What is the output of the below Java program with an abstract class?
public abstract class AbstractClassTest5
{
  public static void main(String[] args)
  {
    System.out.println("Inside Main() method..");
  }
}
A) No output
B) Compiler error
C) Inside Main() method..
D) None of the above
Answer [=]
C
Explanation:

It is perfectly allowed to define a public abstract class as long as you do not create objects of it. Remember that the name of the JAVA file is the name of the public class.



15) What is the output of the below Java code with an abstract class and inner class?
public abstract class AbstractClassTest6
{
  class Anonymous
  {
    int a=5;
  }
  public static void main(String args[])
  {
    System.out.print("Inner class is present..");	
  }	
}
A) Compiler error
B) Inner class is present..
C) No output
D) None of the above
Answer [=]
B
Explanation:

Inner classes are allowed to be written inside an abstract class. So, the program compiles successfully. But to use that inner class, subclassing is necessary.

16) Choose a correct statement about abstract classes?
A) An abstract class can extend a concrete class
B) An abstract class can extend another abstract class
C) An abstract class can implement any number of interfaces.
D) All the above.
Answer [=]
D
Explanation:

Yes. Abstract classes can implement interfaces and extend other classes.

17) Choose correct statements about an Abstract class in Java?
A) An abstract class implementing an Interface, need not implement methods of an interface
B) An abstract class extending another abstract class, need not define methods of the super abstract class.
C) The first subclass of an abstract class should define all the abstract methods inherited from all the interfaces and super abstract classes.
D) All the above
Answer [=]
D
18) Just like an Interface, you can define constants in abstract classes in Java. State TRUE or FALSE.
A) TRUE
B) FALSE
C) -
D) -
Answer [=]
A
Explanation:

TRUE.

19) Abstract classes support ____ inheritance.
A) Multiple
B) Multilevel
C) -
D) -
Answer [=]
B
Explanation:

Just like a concrete/normal class in Java, abstract classes support multilevel inheritance only. You can extend only from one super class.

20) An abstract class can define ____ inside of it.
A) Inner abstract class
B) Inner concrete class
C) static methods
D) All the above
Answer [=]
D