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.
The code runs with no output.

B.
Compilation fails.

C.
str != str2

D.
str = str2



Leave a Reply 0

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