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();


class Child extends Base {

    public String print() {
        return "String from child method";
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
Keep exploring
Java quizzes
Sign Up Now
or Subscribe for future quizzes