Explanation: The compilation fails with the above method since the instance of Class Sub which is sub calls the super() in the above method by default which is not implemented in the Super Class. So this generates a Compilation error. To run this program without compilation error and to print the value 2 it must be coded as given:
class Super
{
public int i = 0;
public Super()
{
}
{
i = 1;
}
}
public class Sub extends Super
{
{
i = 2;
}
public static void main
(String args
[]) {
Sub sub = new Sub("Hello");
}
}
Incorrect Answers:1: The output of 0 will not be provided even if the class is not extended to super as the default value if instance is properly created would be 2
2: The output of 1 will not be provided even if the class is not extended to super as the default value if instance is properly created would be 2
3: The output of 2 will be provided only when the empty super() method exists in Class Super.