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.
Java Quiz
Start Quiz

or Read more about Java Quiz

Follow CodeGalaxy

Mobile Beta

Get it on Google Play
Send Feedback