• Courses
  • Tutorials
  • DSA
  • Data Science
  • Web Tech
Switch to Dark Mode

Java Abstract Class and Interface

Last Updated : Mar 22, 2024
Discuss
Comments

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.
  • A
    Only I
  • B
    Only II
  • C
    Neither I nor II
  • D
    Both I and II

Question 2

In Java, we can make a class abstract by

  • A

    Declaring it abstract using the abstract keyword.

  • B

    Making at least one method final.

  • C

    Declaring all methods as static.

  • D

    Declaring at least one method as abstract.

Question 3

Which of the following is true about an abstract class in Java?

  • A

    An abstract class can be instantiated directly.

  • B

    An abstract class can contain both abstract and non-abstract methods.

  • C

    All methods in an abstract class must be abstract.

  • D

    An abstract class cannot have a constructor.

Question 4

Type IV JDBC driver is a driver

  • A

    which is written in C++

  • B

    which requires an intermediate layer

  • C

    which communicates through Java sockets

  • D

    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

    a = 10

  • B

    a = 20

  • C

    Compilation error

Question 6

Which of the following is FALSE about abstract classes in Java

  • A

    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

  • B

    Abstract classes can have constructors

  • C

    A class can be made abstract without any abstract method

  • D

    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.
  • A

    1, 3 and 4

  • B

    1, 2 and 4

  • C

    2, 3 and 4

  • D

    1, 2, 3 and 4

Master JAVA and also get 90% fee refund on completing 90% course in 90 days! Take the Three 90 Challenge today.

After successfully processing refunds worth over INR 5 Cr, GeeksforGeeks is back with the Three 90 challenge and this is your chance to upskill and get 90% refund. What more motivation do you need? Start the challenge right away!

There are 7 questions to complete.

Take a part in the ongoing discussion