1

Abstract Class and Interface

Question 1
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.
Abstract Class and Interface    
Discuss it


Question 2
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
Abstract Class and Interface    
Discuss it


Question 3
Predict the output of the following program.
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
Abstract Class and Interface    
Discuss it


Question 3 Explanation: 
Final method can’t be overridden. Thus, an abstract function can’t be final.
There are 3 questions to complete.
1

GATE CS Corner


See Placement Course for placement preparation, GATE Corner for GATE CS Preparation and Quiz Corner for all Quizzes on GeeksQuiz.