Complete the code to override the method display in the subclass.
class Parent { void display() { System.out.println("Parent display"); } } class Child extends Parent { @Override void [1]() { System.out.println("Child display"); } }
Complete the code to call the overridden method from the subclass object.
class Parent { void greet() { System.out.println("Hello from Parent"); } } class Child extends Parent { @Override void greet() { System.out.println("Hello from Child"); } } public class Test { public static void main(String[] args) { Child obj = new Child(); obj.[1](); } }
greet.Fix the error in the method overriding by completing the method signature correctly.
class Animal { void sound() { System.out.println("Animal sound"); } } class Dog extends Animal { @Override public [1] sound() { System.out.println("Bark"); } }
Fill both blanks to override the method and call the parent class method inside the overriding method.
class Vehicle { void start() { System.out.println("Vehicle started"); } } class Car extends Vehicle { @Override void [1]() { super.[2](); System.out.println("Car started"); } }
start to override, and super.start() calls the parent method.Fill all three blanks to override the method with a parameter and call the parent method with the same parameter.
class Printer { void print(String message) { System.out.println("Printer: " + message); } } class ColorPrinter extends Printer { @Override void [1](String [2]) { super.[3]([2]); System.out.println("ColorPrinter: " + [2]); } }
print, the parameter name is message, and the parent method is called with super.print(message).