What will be the result of the following code compilation and execution?

public class Base {

    public Object print() {
        return "Object from base method";
    }

    public static void main(String[] args) {
        Base test = new Child();
        System.out.println(test.print());
    }

}

class Child extends Base {

    public String print() {
        return "String from child method";
    }
}
Explanation
Overridden method of the derived class may return a type derived from the type returned by the base class method.

Follow CodeGalaxy

Mobile Beta

Get it on Google Play
Send Feedback