0% found this document useful (0 votes)
2K views

13-MCQs On Abstract Class and Interfaces

The document contains 10 multiple choice questions about abstract classes and methods in Java. It tests understanding of when abstract classes and methods can be declared, overridden, implemented, and whether certain code snippets would compile or not. The correct answers are provided but not discussed here for brevity.

Uploaded by

Akash Saraogi
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
2K views

13-MCQs On Abstract Class and Interfaces

The document contains 10 multiple choice questions about abstract classes and methods in Java. It tests understanding of when abstract classes and methods can be declared, overridden, implemented, and whether certain code snippets would compile or not. The correct answers are provided but not discussed here for brevity.

Uploaded by

Akash Saraogi
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 5

1) Which of the following classes fail to compile?

class X { abstract void method(); }


abstract class Y extends X { }
class Z extends Y { void method() { } }

A. X, Y, Z
B. Y
C. Z
D. X
E. All classes compile

2)Which of the following classes fail to compile?

abstract class X { abstract void method(); }


abstract class Y extends X { }
class Z extends Y { void method() { System.out.println("Class Z"); } }

A. X
B. X, Y
C. Y, Z
D. X, Y, Z
E. All classes compile

3)Which of the following classes fail to compile?

abstract class X { abstract void method(); }


class Y extends X { }
class Z extends Y { void method() { System.out.println("Class Z"); } }
A. X, Y, Z
B. Y, Z
C. Y
D. Z
E. All classes compile

4)Which of the following classes fail to compile?


abstract class X { abstract void method(); }
abstract class Y extends X { }
class Z extends Y { void Method() { System.out.println("Class Z"); } }
A. Z
B. X, Y
C. Y
D. X, Y, Z
E. All classes compile

5)Which of the following classes fail to compile?

abstract class X { abstract void method(); }


abstract class Y extends X { void Method() { } }
class Z extends X { void method() { } }
A. X
B. Y
C. Z
D. X, Y, Z
E. All classes compile

6)Which of the following classes fail to compile?

abstract class X
{
abstract void method();
void method(int i){}
}

abstract class Y
{
abstract void method();
abstract void method1();
}

abstract class Z
{
abstract void method1();
}

A. X
B. X, Z
C. Y, Z
D. X, Y, Z
E. All classes compile

7)Which of the following classes fail to compile.

abstract class I
{
abstract void i1();
}

abstract class J extends I


{
void i1() {}
}

abstract class K extends J


{
abstract void i2();
}

A. I, J, K
B. J, K
C. K
D. All of them compile

8)Which of the following classes fail to compile?

abstract class X
{
abstract void method();
void method(int i);
}

abstract class Y
{
abstract void method();
abstract void method1();
}

abstract class Z
{
abstract void method(){}
}

A. X
B. X, Z
C. Y, Z
D. X, Y, Z
E. All classes compile

9)Which is the following statement(s) is/are correct?


X: A class can be marked as abstract with out containing any abstract method.
Y: If a class has even one abstract method, then the class has to be an abstract class.

A. X only
B. Y only
C. Both are correct
D. Both are incorrect

10) Which program(s) is/are valid?

Program 1:
abstract class A
{
abstract void method1();

abstract void method2() {}

}
Program 2:
abstract class A
{
abstract void method1();

void method2() {}

A. Program 1 is valid
B. Program 2 is valid
C. Both programs are valid
D. Both programs are invalid

10)What will be the output of the following program?

public class Test {


public static void main(String[] args) {
new Z().method1();
new Z().method2();
}
}
abstract class X {
abstract void method1();
abstract void method2();
}
abstract class Y extends X {
void method1() {
System.out.println("Method1 implemented here.");
}
}
class Z extends Y {
void method2() {
System.out.println("Method2 implemented here.");
}
}

A. Method2 implemented here.


B. Method1 implemented here.
C. Method1 implemented here.
Method2 implemented here.
D. Compilation Error or Runtime Error

You might also like