Menu
Question Index
...

What will be the output of the following program?

class Super
{
    public int i = 0;

    public Super(String text)
    {
        i = 1;
    }
}

public class Sub extends Super
{
    public Sub(String text)
    {
        i = 2;
    }

    public static void main(String args[])
    {
        Sub sub = new Sub("Hello");
        System.out.println("i = " + sub.i);
    }
}


i = 0
i = 1
i = 2
Compilation Error
Runtime Error

Doubts

Problems

Topic: Inheritance And Constructors In Java

Read this topic
Take test on this topic

0
Wrong
Score more than 2 points

© meritcampus 2019

All Rights Reserved.

Open In App