AlgoMaster Logo

Inheritance - Quiz

Last Updated: January 13, 2026

1 min read

Inheritance Exercises

23 quizzes

1
Code Completion

Make the Dog class inherit the behavior of the Animal class

java
1
class Dog Animal {

Click an option to fill the blank:

2
Code Completion

Override the start method in the ElectricCar subclass

java
1
@Override
2
public void () {

Click an option to fill the blank:

3
Multiple Choice

Which statement best describes inheritance in Java?

4
Multiple Choice

What does the extends keyword indicate in a class declaration?

5
Multiple Choice

Which use of super is valid inside a subclass method?

6
Multiple Choice

When a subclass overrides a non-static method from its superclass, which method is called at runtime?

7
Multiple Choice

What happens if a subclass constructor does not explicitly call super(...)?

8
Multiple Choice

Which class is at the top of the inheritance hierarchy in Java?

9
Multiple Choice

Which statement about the equals method from Object is true if a class does NOT override it?

10
Multiple Choice

Which methods a subclass cannot override from its superclass?

11
Multiple Choice

In a constructor, what is required if you use super(...)?

12
Sequencing

Order the steps to create a subclass that overrides a method from its superclass.

Drag and drop to reorder, or use the arrows.

13
Output Prediction

What is the output of this code?

1class Vehicle {
2    String name = "Vehicle";
3    void printName() {
4        System.out.println(name);
5    }
6}
7class Car extends Vehicle {
8    String name = "Car";
9    @Override
10    void printName() {
11        System.out.println(name);
12    }
13}
14public class Main {
15    public static void main(String[] args) {
16        Vehicle v = new Car();
17        v.printName();
18    }
19}
14
Output Prediction

What is the output of this code?

1class Animal {
2    void sound() {
3        System.out.println("Animal");
4    }
5}
6class Dog extends Animal {
7    @Override
8    void sound() {
9        super.sound();
10    }
11}
12public class Main {
13    public static void main(String[] args) {
14        Dog d = new Dog();
15        d.sound();
16    }
17}
15
Output Prediction

What is the output of this code?

1class Base {
2    Base() {
3        System.out.print("Base");
4    }
5}
6class Derived extends Base {
7    Derived() {
8        System.out.print("Derived");
9    }
10}
11public class Main {
12    public static void main(String[] args) {
13        new Derived();
14    }
15}
16
Output Prediction

What is the output of this code?

1class Person {
2    public String toString() {
3        return "Person";
4    }
5}
6public class Main {
7    public static void main(String[] args) {
8        Person p = new Person();
9        System.out.println(p.toString());
10    }
11}
17
Output Prediction

What is the output of this code?

1class Animal {}
2class Dog extends Animal {}
3public class Main {
4    public static void main(String[] args) {
5        Animal a = new Dog();
6        boolean result = a instanceof Dog;
7        System.out.println(result);
8    }
9}
18
Matching

Match each Object class method with its primary purpose.

Click an item on the left, then click its match on the right. Click a matched item to unmatch.

19
Matching

Match each inheritance-related keyword or operator with its role.

Click an item on the left, then click its match on the right. Click a matched item to unmatch.

20
Fill in the Blanks

Complete the code so that Developer inherits from Employee and correctly uses the superclass constructor.

java
1
class Employee {
2
String name;
3
Employee(String name) {
4
this.name = name;
5
}
6
}
7
class Developer Employee {
8
String language;
9
Developer(String name, String language) {
10
(name);
11
this.language = language;
12
}
13
}

Click an option to fill blank 1:

21
Fill in the Blanks

Complete the code so that the overridden start method in Car still calls the Vehicle implementation first.

java
1
class Vehicle {
2
void start() {
3
System.out.println("Vehicle starting");
4
}
5
}
6
class Car extends Vehicle {
7
@Override
8
void start() {
9
.start();
10
System.out.println("Car ready");
11
}
12
}
13
public class Main {
14
public static void main(String[] args) {
15
Vehicle v = new Car();
16
v.();
17
}
18
}

Click an option to fill blank 1:

22
Fill in the Blanks

Complete the code so that the Manager class correctly chains constructors with this and super.

java
1
class Person {
2
String name;
3
Person(String name) {
4
this.name = name;
5
}
6
}
7
class Manager extends Person {
8
int teamSize;
9
Manager(String name) {
10
(name, 0);
11
}
12
Manager(String name, int teamSize) {
13
(name);
14
this.teamSize = teamSize;
15
}
16
}

Click an option to fill blank 1:

23
Hotspot Selection

Click the line where the overridden method in Dog is declared.

Click on the line to select.

java
1
class Animal {
2
    void speak() {
3
        System.out.println("Animal");
4
    }
5
}
6
class Dog extends Animal {
7
    @Override
8
    void speak() {
9
        System.out.println("Dog");
10
    }
11
}
12
public class Main {
13
    public static void main(String[] args) {
14
        Animal a = new Dog();
15
        a.speak();
16
    }
17
}