Java Interfaces, Abstract Classes & Multiple Inheritance Quiz
35 in-depth questions (15 with code) covering interface basics, abstract class fundamentals, default/static methods in interfaces, functional interfaces, and multiple inheritance resolution in Java.
Question 1
What is the primary difference between an interface and an abstract class?
Question 2
Can an interface have instance variables?
Question 3
What is an abstract class?
Question 4
Can an abstract class have constructors?
Question 5
What is a default method in an interface?
Question 6
What is a functional interface?
Question 7
How does Java resolve the diamond problem in multiple inheritance?
Question 8
Can an interface extend multiple interfaces?
Question 9
What is the output of this interface implementation example?
interface Animal {
void makeSound();
}
class Dog implements Animal {
public void makeSound() { System.out.println("Woof"); }
}
public class Test {
public static void main(String[] args) {
Animal a = new Dog();
a.makeSound();
}
}Question 10
What happens when a class implements multiple interfaces with the same method signature?
Question 11
Can an abstract class implement an interface?
Question 12
What is a static method in an interface?
Question 13
What is the result of this abstract class example?
abstract class Vehicle {
abstract void start();
void stop() { System.out.println("Stopping"); }
}
class Car extends Vehicle {
void start() { System.out.println("Car starting"); }
}
public class Test {
public static void main(String[] args) {
Vehicle v = new Car();
v.start();
v.stop();
}
}Question 14
What is the @FunctionalInterface annotation used for?
Question 15
How do default methods resolve conflicts in multiple inheritance?
Question 16
Can an interface have private methods?
Question 17
What is the output of this multiple interface implementation?
interface A { default void show() { System.out.println("A"); } }
interface B { default void show() { System.out.println("B"); } }
class C implements A, B {
public void show() { System.out.println("C"); }
}
public class Test {
public static void main(String[] args) {
new C().show();
}
}Question 18
When should you use an interface instead of an abstract class?
Question 19
What is the result of this functional interface with lambda?
interface Calculator {
int calculate(int a, int b);
}
public class Test {
public static void main(String[] args) {
Calculator add = (a, b) -> a + b;
System.out.println(add.calculate(5, 3));
}
}Question 20
Can an abstract class have final methods?
Question 21
What is the output of this interface with static method?
interface MathUtils {
static int square(int x) { return x * x; }
}
public class Test {
public static void main(String[] args) {
System.out.println(MathUtils.square(5));
}
}Question 22
How do private methods in interfaces work?
Question 23
What happens when an abstract class implements an interface?
Question 24
What is the result of this default method inheritance?
interface Parent {
default void show() { System.out.println("Parent"); }
}
class Child implements Parent {
// No override
}
public class Test {
public static void main(String[] args) {
new Child().show();
}
}Question 25
Can a class implement multiple interfaces with default methods that conflict?
Question 26
What is the purpose of abstract classes in framework design?
Question 27
What is the output of this complex inheritance example?
interface A { default void m() { System.out.println("A"); } }
interface B { default void m() { System.out.println("B"); } }
abstract class C implements A, B {
public void m() { System.out.println("C"); }
}
class D extends C {}
public class Test {
public static void main(String[] args) {
new D().m();
}
}Question 28
Why are functional interfaces important for modern Java?
Question 29
Can an interface extend an abstract class?
Question 30
What is the result of this interface constant example?
interface Constants {
int MAX = 100;
String NAME = "Java";
}
public class Test implements Constants {
public static void main(String[] args) {
System.out.println(MAX + " " + NAME);
}
}Question 31
How do default methods affect the single responsibility principle?
Question 32
What is the output of this abstract class constructor example?
abstract class Base {
Base() { System.out.println("Base constructor"); }
}
class Derived extends Base {
Derived() { System.out.println("Derived constructor"); }
}
public class Test {
public static void main(String[] args) {
new Derived();
}
}Question 33
Why are interfaces preferred for dependency injection?
Question 34
What is the result of this functional interface with method reference?
interface Processor {
String process(String s);
}
public class Test {
public static void main(String[] args) {
Processor upper = String::toUpperCase;
System.out.println(upper.process("hello"));
}
}Question 35
Mastering interfaces and abstract classes means you now design code that:
