Last Updated: January 3, 2026
31 quizzes
Make the Dog class inherit the behavior of the Animal class
class Dog Animal {Click an option to fill the blank:
Call the parent class constructor to initialize the title field
super();Click an option to fill the blank:
Override the start method in the ElectricCar subclass
@Overridepublic void () {Click an option to fill the blank:
Which statement best describes inheritance in Java?
What does the extends keyword indicate in a class declaration?
Which use of super is valid inside a subclass method?
When a subclass overrides a non-static method from its superclass, which method is called at runtime?
What happens if a subclass constructor does not explicitly call super(...)?
Which class is at the top of the inheritance hierarchy in Java?
Which statement about the equals method from Object is true if a class does NOT override it?
Which expression correctly tests whether an Animal reference refers to a Dog object?
Which methods in a subclass cannot override methods from its superclass?
In a constructor, what is required if you use super(...)?
Which statement about instanceof and null is correct?
Order the steps to create a subclass that overrides a method from its superclass.
Drag and drop to reorder, or use the arrows.
Order the steps to properly use constructor chaining with super in an inheritance hierarchy.
Drag and drop to reorder, or use the arrows.
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}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}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}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}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}Find the bug in this inheritance-based class design that should compare employees by id.
Click on the line(s) that contain the bug.
class Employee { private int id; public Employee(int id) { this.id = id; } public boolean equals(Employee other) { return this.id == other.id; }}public class Main { public static void main(String[] args) { Employee e1 = new Employee(1); Employee e2 = new Employee(1); System.out.println(e1.equals(e2)); }}Find the bug related to calling the superclass constructor.
Click on the line(s) that contain the bug.
class Vehicle { private String type; public Vehicle(String type) { this.type = type; }}class Car extends Vehicle { private String model; public Car(String model) { this.model = model; }}public class Main { public static void main(String[] args) { Car car = new Car("Sedan"); System.out.println("Done"); }}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.
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.
Complete the code so that Developer inherits from Employee and correctly uses the superclass constructor.
class Employee { String name; Employee(String name) { this.name = name; }}class Developer Employee { String language; Developer(String name, String language) { (name); this.language = language; }}Click an option to fill blank 1:
Complete the code so that the overridden start method in Car still calls the Vehicle implementation first.
class Vehicle { void start() { System.out.println("Vehicle starting"); }}class Car extends Vehicle { @Override void start() { .start(); System.out.println("Car ready"); }}public class Main { public static void main(String[] args) { Vehicle v = new Car(); v.(); }}Click an option to fill blank 1:
Complete the code to override toString and use instanceof for safe casting.
class Animal {}class Cat extends Animal { String name; Cat(String name) { this.name = name; } @Override public String () { return "Cat:" + name; }}public class Main { public static void printIfCat(Animal a) { if (a Cat) { Cat c = (Cat) a; System.out.println(c.()); } }}Click an option to fill blank 1:
Complete the code so that the Manager class correctly chains constructors with this and super.
class Person { String name; Person(String name) { this.name = name; }}class Manager extends Person { int teamSize; Manager(String name) { (name, 0); } Manager(String name, int teamSize) { (name); this.teamSize = teamSize; }}Click an option to fill blank 1:
Click the line where the overridden method in Dog is declared.
Click on the line to select.
class Animal { void speak() { System.out.println("Animal"); }}class Dog extends Animal { @Override void speak() { System.out.println("Dog"); }}public class Main { public static void main(String[] args) { Animal a = new Dog(); a.speak(); }}Click the line where the instanceof operator is used to check the runtime type.
Click on the line to select.
class Shape {}class Circle extends Shape {}public class Main { public static void main(String[] args) { Shape s = new Circle(); if (s instanceof Circle) { System.out.println("Circle detected"); } }}