Menu
Topics Index
...
`

Runs


If you need explanation Read this topic

If you need Answer Take test on this topic

Runs
What will be the output of the following program?
public class Bowler {
    int runs = 81;
    public static void main(String[] args) {
        new Bowler().go();
    }
    int balls = 75;
    void go() {
        incr(++runs);
        dec(--balls);
        System.out.print(runs + ",");
        System.out.print(balls + ",");
    }
    void incr(int runs) {
        runs += 10;
    }
    void dec(int balls) {
        balls -= 20;
        System.out.print(balls + ",");
    }
}

A. 82,54,74,
B. 54,74,82
C. 82,55,74
D. 54,82,74,
E. Compilation Error or Runtime Error.
Topic: Java Multiple Methods In One Class

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 D runs is incremented by one and passed to method where formal parameters runs is incremented by 10 and again balls is pre decremented by one and passed to method where formal parametres are changed and printed der 54,and again balls and runs are printed which are not modified by methods and hence 82,74, are printed..(based on scope of variables).

Posted by Vicky Maduri    2014-06-25 04:21:07


answ is b...in methods if we change global variable it wnt effect unles it is static variable

Posted by Vijay Kumar    2014-06-25 04:38:27


E

Posted by Htwe Ei Hlaing    2014-06-25 04:59:29


D

Posted by Shri Nandhitha    2014-06-25 05:02:35


Answer is E as compiler doesn't find .go()method in .class file which was not created ...

Posted by Sasikanth Sharma    2014-06-25 05:04:46


i think 'A'

Posted by Aashish Jain    2014-06-25 05:18:52


e

Posted by Sudhakar Dhs    2014-06-25 05:57:34


e  bcoz we cannot declare go() mehtod with the new bolwer

Posted by Prince Dhiman    2014-06-25 08:06:40


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

Posted by Merit Campus    2014-06-26 04:34:41


© meritcampus 2019

All Rights Reserved.

Open In App