Menu
Topics Index
...
`

good and bad


If you need explanation Read this topic

If you need Answer Take test on this topic

good and bad
What will be the output of the following program?
class PassS {
    public static void main(String[] args) {
        PassS p = new PassS();
        p.start();
    }
    void start() {
        String s1 = "good";
        String s2 = fix(s1);
        System.out.println(s1 + " " + s2);
    }
    String fix(String s1) {
        s1 = s1 + "bad";
        System.out.print(s1 + " ");
        return "bad";
    }
}

A. good bad
B. goodbad bad
C. goodbad good bad
D. bad good bad
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.

option c since first return in fix method is executed then the strt's print statements

Posted by Karteek Paruchuri    2013-06-11 04:23:45


It is option C...first goodbad good bad

Posted by Jayachandra Gupta    2013-06-11 04:23:46


ans is c: as s1 containes goodbad and functn returns bad which is stored in s2 and good space bad is printed

Posted by Krishna Murthy    2013-06-11 04:24:27


Congratulations Karteek Paruchuri. You are this daily dose's winner. Please send us the mobile details and we will process the recharge asap.

Posted by Merit Campus    2013-06-11 08:40:59


got the RC thank you

Posted by Karteek Paruchuri    2013-06-16 06:31:11


© meritcampus 2019

All Rights Reserved.

Open In App