What is the result?

Given:
1. class Test {
2. public static void main(String args[]) {
3. String str = “Hello!”;
4. String str2 = “Bye!”;

5. str += str2;
6. str -= str2;
7.
8. if ( str == str2 ) {
9. System.out.println(“str = str2”);
10. } else {
11. System.out.println(“str != str2”);
12. }
13. }
14. }
What is the result?

Given:
1. class Test {
2. public static void main(String args[]) {
3. String str = “Hello!”;
4. String str2 = “Bye!”;

5. str += str2;
6. str -= str2;
7.
8. if ( str == str2 ) {
9. System.out.println(“str = str2”);
10. } else {
11. System.out.println(“str != str2”);
12. }
13. }
14. }
What is the result?

A.
str != str2

B.
str = str2

C.
The code runs with no output.

D.
Compilation fails.



Leave a Reply 0

Your email address will not be published. Required fields are marked *