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.
You should precede the keyword "abstract" before the keyword "class".
True. You create a class using the keyword CLASS and make it abstract using the keyword ABSTRACT.
abstract class ClassA{ }
No. You can not instantiate or create an object from an abstract class.
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.
abstract class ClassA { }
abstract class ClassB { abstract void method(); }
abstract class ClassC { void method() { System.out.print("Hello Abstract Class"); } }
All the above. An abstract class need not contain a single abstract method also.
Developers usually write abstract classes with one or more abstract methods to be implemented after inheriting the class.
class Puppy { abstract void showName(); }
No. An abstract method can be defined only by 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(); } }
Inside Constructor of Coffee.. Inside Constructor of ColdCoffee..
Inside Constructor of ColdCoffee..
Inside Constructor of Coffee..
An abstract class can contain constructors. The order of invoking of constructors is from the Superclass to Subclass.
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(); } }
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.
abstract class MathLibrary { static final float PI = 3.1415f; } public class AbstractClassTesting3 { public static void main(String[] args) { System.out.println(MathLibrary.PI); } }
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.
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(); } }
Editor method Editor method
Author method Author method
Editor method Author method
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.
True. You can not create objects out of an abstract class whether it is single level or multilevel.
An interface contains only abstract methods. So it is comparable to a 100% abstract class.
public abstract class AbstractClassTest5 { public static void main(String[] args) { System.out.println("Inside Main() method.."); } }
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.
public abstract class AbstractClassTest6 { class Anonymous { int a=5; } public static void main(String args[]) { System.out.print("Inner class is present.."); } }
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.
Yes. Abstract classes can implement interfaces and extend other classes.
TRUE.
Just like a concrete/normal class in Java, abstract classes support multilevel inheritance only. You can extend only from one super class.