Vidyalelo
Java Programming · all questions

Interfaces and Abstract Classes
practice.

Practice every MCQ with options. Use Show answers when you want the correct option and solution.

309

Questions

1/16

Page

Pick an option on a question to see the right answer and solution.

What is an interface in Java?

Select an option to see the answer and solution.

In Java, can a class implement multiple interfaces?

Select an option to see the answer and solution.

Which keyword is used to declare an interface in Java?

Select an option to see the answer and solution.

What is the purpose of an abstract class in Java?

Select an option to see the answer and solution.

In Java, can an abstract class be instantiated?

Select an option to see the answer and solution.

What is the purpose of the "implements" keyword in Java?

Select an option to see the answer and solution.

Which of the following can contain both abstract and non-abstract methods?

Select an option to see the answer and solution.

In Java, can an interface have fields (member variables)?

Select an option to see the answer and solution.

What is the purpose of an abstract method in an abstract class or interface?

Select an option to see the answer and solution.

Which keyword is used to define an abstract method in Java?

Select an option to see the answer and solution.

In Java, can an interface have private methods with implementations?

Select an option to see the answer and solution.

What is the result of the following code snippet?

interface MyInterface {
void myMethod();
}
public class MyClass implements MyInterface {
public void myMethod() {
System.out.println("Implementation");
}
public static void main(String[] args) {
MyInterface obj = new MyClass();
obj.myMethod();
}
}

Select an option to see the answer and solution.

In Java, can an abstract class extend another class?

Select an option to see the answer and solution.

What is the purpose of the "extends" keyword in Java?

Select an option to see the answer and solution.

In Java, can an interface extend another interface?

Select an option to see the answer and solution.

What is the result of the following code snippet?

abstract class MyAbstract {
abstract void myMethod();
}
class MyClass extends MyAbstract {
void myMethod() {
System.out.println("Implementation");
}
public static void main(String[] args) {
MyAbstract obj = new MyClass();
obj.myMethod();
}
}

Select an option to see the answer and solution.

In Java, can an abstract class have non-abstract methods?

Select an option to see the answer and solution.

What is the purpose of the "default" keyword in Java interfaces?

Select an option to see the answer and solution.

What is the result of the following code snippet?

interface MyInterface {
default void myMethod() {
System.out.println("Default Implementation");
}
}
class MyClass implements MyInterface {
public static void main(String[] args) {
MyInterface obj = new MyClass();
obj.myMethod();
}
}

Select an option to see the answer and solution.

In Java, can a class implement an interface and extend an abstract class simultaneously?

Select an option to see the answer and solution.