Java Abstract Class MCQ Questions

This section focuses on the "Abstract class" in Java programming language. These Multiple Choice Questions (MCQ) should be practiced to improve the Java programming skills required for various interviews (campus interviews, walk-in interviews, company interviews), placements, entrance exams and other competitive examinations.

1. A class which is declared with the ________ keyword is known as an abstract class in Java.

A. abstract
B. util
C. extends
D. None of the above

View Answer


2. Abstract class can have constructors and static methods?

A. TRUE
B. FALSE
C. Abstract class can have constructors but can not have static methods.
D. Abstract class can not have constructors but can have static methods.

View Answer


3. What is the syntax of abstract class in java?

A. abstract A{}
B. abstract class A
C. abstract class A{}
D. abstract class A[]

View Answer


4. Which of these is not abstract?

A. Thread
B. AbstractList
C. List
D. None of the Mentioned

View Answer


5. A method which is declared as abstract and does not have implementation is known as an _____________?

A. Abstract Interface
B. Abstract Thread
C. Abstract List
D. abstract Method

View Answer


6. Which of these packages contains abstract keyword?

A. java.lang
B. java.util
C. java.io
D. java.system

View Answer


7. An abstract class can have a data member, abstract method, method body (non-abstract method), constructor, and even main() method.

A. TRUE
B. FALSE
C. Can be true or false
D. can not say

View Answer


8. Which of these is not a correct statement?

A. Every class containing abstract method must be declared abstract
B. Abstract class defines only the structure of the class not its implementation
C. Abstract class can be initiated by new operator
D. Abstract class can be inherited

View Answer


9. What will be output for the folllowing code?

         
abstract class Bank {

  private abstract void withdraw(); // Line 1
  abstract void deposit();
  public void balance(){} //Line 2
}
class office extends Bank{ // Line 3

  void deposit() { // Line 4
    // TODO Auto-generated method stub

  }
}

A. Compilation error in Line 1(abstract method cannot be private)
B. Compilation error in Line 2(abstract class cannot have concrete method)
C. Compilation error in Line 3(abstract class cannot be extended)
D. Compilation error in Line 4(deposit method should have public access modifier)

View Answer


10. What will be output for the folllowing code?

abstract class Bank 
{

    private String bankName;

    Bank(String bankName) 
    {
        this.bankName = bankName;
    }

    public String getBankName() 
    {
    return bankName;
    }
}

class office extends Bank {

  office() {
    super("Axis Bank");
  }

  public static void main(String[] args) {
    Bank bank = new office();
    System.out.println(bank.getBankName());
  }

}

A. Compilation error will occur because ""abstract class cannot have constructor""
B. Compilation error will occur because ""abstract class must have an abstract method""
C. Compilation error will occur while invoking the super class constructor
D. Code will be compiled successfully

View Answer





Discussion



* You must be logged in to add comment.