Can I change a method's return type present in the child class, when both the methods present in the Parent and Child classes have same parameters?

Viewed 9
class Vehicle {
    public void show() {
        System.out.println("Parent");
    }
}
class Car extends Vehicle{
    public int show() {
        System.out.println("Child");
        return 3;
    }
}

When I am trying to override Car class' method in child class, it is showing error but when I specify a parameter in the method, the error goes away.

0 Answers
Related