Menu
Topics Index
...
`

Water Bottle and hai


If you need explanation Read this topic

If you need Answer Take test on this topic

Water Bottle and hai
What will be the output of the following program?
public class WaterBottle {

    public static void main(String[] args) {
        WaterBottle s = new WaterBottle();
        s.start();
    }
    
    void start() {
        int a = 3;
        int b = 4;
        System.out.print("_" + 7 + 2 + "_");
        System.out.print(a + b);
        System.out.print("_" + a + b + "_");
        System.out.print(hai() + a + b + "_");
        System.out.println(a + b + hai());
    }
    
    String hai() {
        return "hai";
    }
}

A. _9_7_7_hai_7_7hai
B. _72_34_34_hai34_34hai
C. _9_7_7_hai34_34hai
D. _72_7_34_hai34_7hai
E. Compilation Error or Runtime Error
Topic: Java String Concatenation with Other Data Types

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 d is the ans bcs numericals are printed as it is and int values are added in 2nd and in 3rd print due to precision 34 prints and so on..

Posted by Sai Lalitha Renduchintala    2013-04-26 12:52:33


answer is D,in main method vn start is called,,it goes to S.o.p and prints 72 and underscores as it is..where as the intiliazied values that is A,B are added up if it is in the 1st position of the S.O.P or else it just prints the values that are initialised..if last SOP it is appending where as it is not d case for the other SOP's..

Posted by Shaik Nyamath    2013-04-26 13:09:10


ans is d
when we r using nly variables and functns in s.o.p, values of a and b are added r else they are printed as it is...

Posted by Ramana Tadakamalla    2013-04-26 13:32:28


Congratulations Shaik Nyamath. You are today's daily dose winner. Please send us your mobile number and operator details in a message and we will process the recharge on Monday after considering the new likes.

Posted by Merit Campus    2013-04-26 16:17:08


Got RC ! thnkQ MC ! :)

Posted by Shaik Nyamath    2013-04-29 14:05:29


© meritcampus 2019

All Rights Reserved.

Open In App