Menu
Question Index
...

What will be the output of the following program?

class OutPut
{
    public static void main(String s[])
    {
        int i = 2;
        B b = new B();
        b.execute();
    }
}

class A
{
    int i = 0;
    A(){}
}

class B extends A
{
    void execute()
    {
        for(; i < 6; i++)
        
            switch(i)
            {
                case 0:
                System.out.println("i is zero.");
                break;
        
                case 1:
                System.out.println("i is one.");
                break;
        
                case 2:
                System.out.println("i is two.");
                continue;
        
                case 3:
                System.out.println("i is three.");
                break;
        
                default:
                System.out.println("i is greater than three.");
            }
    }
}


i is zero.
i is one.
i is two.
i is three.
i is three.
i is greater than three.
i is greater than three.
i is zero.
i is one.
i is two.
i is three.
i is greater than three.
i is greater than three.
i is two.
i is three.
i is three.
i is greater than three.4
i is greater than three.5
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