Menu
Topics Index
...
`

Creating object for class1902


If you need explanation Read this topic

If you need Answer Take test on this topic

Creating object for class1902
What will be the output of the following program?
public class MTR {
    void method1(String str, int x) {
        str = new String("Hot");
        x = x + 1;
    }
    public static void main(String s[]) {
        String str1 = "Sweet";
        String str2 = "Sweet";
        int a = 1;
        new MTR().method1(str1, 10);
        new MTR().method1(str2, 20);
        System.out.println(str1 + " " + str2 + " " + a);
    }
}

A. Hot Hot
B. Hot 2 Hot 2
C. Sweet Sweet 1
D. Some other output
E. Compilation Error or Runtime Error
Topic: Conclusion Of Strings 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 : d
op: hot hot 1
int function cal string passed as call by reference

Posted by Ananda Kumar    2014-05-05 12:52:02


Ans: C in method1 str is local variable hence str variable data will ot be available in main() method. the variables data in main method will be printed

Posted by Indrasena Reddy    2014-05-05 12:54:29


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

Posted by Merit Campus    2014-05-06 04:21:39


© meritcampus 2019

All Rights Reserved.

Open In App