• Courses
  • Tutorials
  • Jobs
  • Practice
  • Contests

Java Abstract Class and Interface

Question 1

Which of the following statement(s) with regard to an abstract class in JAVA is/are TRUE ? I. An abstract class is one that is not used to create objects. II. An abstract class is designed only to act as a base class to be inherited by other classes.
  • Only I
  • Only II
  • Neither I nor II
  • Both I and II

Question 2

We can make a class abstract by
  • Declaring it abstract using the virtual keyword
  • Making at least one member function as virtual function
  • Making at least one member function as pure virtual function
  • Making all member function const

Question 3

Which of the following is used to make an Abstract class?
  • Making atleast one member function as pure virtual function
  • Making atleast one member function as virtual function
  • Declaring as Abstract class using virtual keyword
  • Declaring as Abstract class using static keyword

Question 4

Type IV JDBC driver is a driver
  • which is written in C++
  • which requires an intermediate layer
  • which communicates through Java sockets
  • which translates JDBC function calls into API not native to DBMS

Question 5

Predict the output of the following program. Java
abstract class demo
{
    public int a;
    demo()
    {
        a = 10;
    }

    abstract public void set();
    
    abstract final public void get();

}

class Test extends demo
{

    public void set(int a)
    {
        this.a = a;
    }

    final public void get()
    {
        System.out.println(\"a = \" + a);
    }

    public static void main(String[] args)
    {
        Test obj = new Test();
        obj.set(20);
        obj.get();
    }
}
 
  • a = 10
  • a = 20
  • Compilation error

Question 6

Which of the following is FALSE about abstract classes in Java
  • If we derive an abstract class and do not implement all the abstract methods, then the derived class should also be marked as abstract using \'abstract\' keyword
  • Abstract classes can have constructors
  • A class can be made abstract without any abstract method
  • A class can inherit from multiple abstract classes.

Question 7

Which of the following is true about interfaces in java.

1) An interface can contain following type of members.
....public, static, final fields (i.e., constants) 
....default and static methods with bodies

2) An instance of interface can be created.

3) A class can implement multiple interfaces.

4) Many classes can implement the same interface.
  • 1, 3 and 4

  • 1, 2 and 4

  • 2, 3 and 4

  • 1, 2, 3 and 4

There are 7 questions to complete.

Last Updated :
Take a part in the ongoing discussion