Complete the code to declare a child class that inherits from a parent class.
class Child [1] Parent {}
In Java, a child class inherits from a parent class using the extends keyword.
Complete the code to call the parent class constructor from the child class constructor.
class Child extends Parent { Child() { [1](); } }
The super() call invokes the parent class constructor in Java.
Fix the error in the child class method overriding the parent method.
class Parent { void greet() { System.out.println("Hello from Parent"); } } class Child extends Parent { @Override void [1]() { System.out.println("Hello from Child"); } }
The child class must use the exact method name greet to override the parent method.
Fill both blanks to create a constructor in the child class that calls the parent constructor with a parameter.
class Parent { Parent(String name) { System.out.println("Parent name: " + name); } } class Child extends Parent { Child(String name) { [1]([2]); } }
The child constructor calls the parent constructor using super(name); passing the parameter.
Fill all three blanks to override a method in the child class and call the parent method inside it.
class Parent { void display() { System.out.println("Parent display"); } } class Child extends Parent { @Override void [1]() { [2].[3](); System.out.println("Child display"); } }
The child overrides display() and calls the parent method with super.display();.