Which code fragment can replace the if block? 10/29/2018 – by Mod_GuideK 5 Given: Which code fragment can replace the if block? A. Option A B. Option B C. Option C D. Option D SHOW ANSWERSCorrect Answer: B Explanation/Reference: Download Printable PDF. VALID exam to help you PASS.
Option D String stuff =”TV”; String res = null; res = stuff.equals(“TV”) ? “Walter” : stuff.equals(“Movie”) ? “White”:”No Result”; System.out.println(“Result ::”+res); Result ::Walter 1 Reply
only D is written correctly from language syntax rules point of view and will be compiled successfully: # javac Test40.java # java Test40 res= Walter 1 Reply
D
Option D
String stuff =”TV”;
String res = null;
res = stuff.equals(“TV”) ? “Walter” : stuff.equals(“Movie”) ? “White”:”No Result”;
System.out.println(“Result ::”+res);
Result ::Walter
only D is written correctly from language syntax rules point of view and will be compiled successfully:
# javac Test40.java
# java Test40
res= Walter
D
Answer is D