Menu
Topics Index
...
`

Interface1377


If you need explanation Read this topic

If you need Answer Take test on this topic

Interface1377
What will be the output of the following program?
interface Fan {
    short counter = 0;
    void countUp(int k);
}
public class AirConditioner implements Fan {
    public static void main(String[] args) {
        AirConditioner t = new AirConditioner();
        t.countUp(counter);
    }
    public void countUp(int k) {
        for (int x = 6; x > k; x--, ++k) {
            System.out.print(k + " ");
        }
    }
}

A. 0 1 2
B. 1 2 3
C. 0 1 2 3
D. 1 2 3 4
E. Compilation Error or Runtime Error
Topic: Creating Interface In Java With Example Program

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 is A..countUp method gets called.
for x=6,x=5,x=4 the condition x>k suceeds and 0,1,2 gets printed

Posted by Krishna Sai    2014-07-28 08:53:47


A is ans.. bcz.. v r prtng k values from 0 by incrmntg until 3>3 gets false so only 0 1 2 is ans

Posted by Shabaaz Shaikz    2014-07-28 08:56:02


A

Posted by Prabhakar Reddy    2014-07-28 09:25:15


A

Posted by Arul Palanisamy    2014-07-28 09:32:47


a here the increment operator decides the loop situation

Posted by Din Kurth    2014-07-29 00:43:46


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

Posted by Merit Campus    2014-07-29 04:36:49


© meritcampus 2019

All Rights Reserved.

Open In App