Last Updated: January 13, 2026
23 quizzes
Make the Dog class inherit the behavior of the Animal class
class Dog Animal {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 methods a subclass cannot override from its superclass?
In a constructor, what is required if you use super(...)?
Order the steps to create a subclass that overrides a method from its superclass.
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}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 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(); }}