GIAC
GSSP-JAVA · Question #157
Mark works as a Software Developer for ZenTech Inc. He writes the following code. 1. public class Ques0352 { 2. public static void main(String[] args) { 3. String s1="JavaObject"; 4. String…
The correct answer is D. It will give a compile-time error at line 4. See the full explanation below for the reasoning.
Question
Mark works as a Software Developer for ZenTech Inc. He writes the following code. 1. public class Ques0352 { 2. public static void main(String[] args) { 3. String s1="JavaObject"; 4. String s1="ObjectJava"; 5. String s2="ObjectJava"; 6. if(s2.equals(s1)) 7. { System.out.println("Equal"); } 8. else 9. { System.out.println("Unequal"); } 10. } 11. } Which of the following will happen to the code when he attempts to compile and run it?
Options
- AIt will compile successfully and Unequal will be displayed as output.
- BIt will give a compile-time error at line 3.
- CIt will compile successfully and Equal will be displayed as output.
- DIt will give a compile-time error at line 4.
How the community answered
(40 responses)- A13% (5)
- B3% (1)
- C8% (3)
- D78% (31)
Community Discussion
No community discussion yet for this question.