Menu
Topics Index
...
`

Classes860


If you need explanation Read this topic

If you need Answer Take test on this topic

Classes860
What will be the output of the following program?
class OutPut
{
    public static void main(String [] args)
    {
        Count2 count = new Count2();
        count.count();
    }
}

class Count extends Count2
{
    Count()
    {

    }
}
class Count2
{
    void count()
    {
        int i = 5;
        System.out.print("Output = ");

        for (int x = 0; x <= (i % 7); x += 1)
        {
            System.out.print(" " + x);
            i++;
        }
    }
}

A. Output = 0 1 2 3 4 5 6 7
B. Output = 0 1 2 3
C. Output = 0 1
D. Output = 0 1 2 3 4 5 6 7 8
E. Compilation Error
Topic: Inheritance And Constructors In Java

If you need explanation Read this topic

If you need Answer Take test on this topic

User comments below. All of them might not be correct.

ans c 0 1
fr x=2
x<=0 so loop fails

Posted by Maheshwari Natarajan    2014-07-07 09:01:46


option c
intially count() method is called by object count
i is intalized with i=5, 5%7=5 ,x=0<=5 condition satisfies..
latter i is incremented and x is also incremented by 1
i=6,6%7=6,x=1<=6 condition satisfies..
latter
i=7,7%7=0,x=2 dosent satisfy condition so loop breaks.

Posted by Sasikanth Sharma    2014-07-07 09:20:06


Ans C : after at 3rd iteration i=7 , x=3

Posted by BalRam At    2014-07-07 09:30:36


C

Posted by Sirajudeen Nowshath    2014-07-07 09:39:01


C

Posted by Rishav Seksaria    2014-07-07 12:28:59


C

Posted by Venkatesh Kotte    2014-07-07 14:39:12


ans is c....

Posted by Muzakir Ahmed    2014-07-07 14:46:44


Congratulations Maheshwari Natarajan. You are this dose winner. We will send you the link using which you can claim your recharge.

Posted by Merit Campus    2014-07-08 04:29:39


© meritcampus 2019

All Rights Reserved.

Open In App