

MCQOPTIONS
Saved Bookmarks
This section includes 52 Mcqs, each offering curated multiple-choice questions to sharpen your Java Programming knowledge and support exam preparation. Choose a topic below to get started.
51. |
public void test(int x) { int odd = 1; if(odd) /* Line 4 */ { System.out.println("odd"); } else { System.out.println("even"); } } Which statement is true? |
A. | Compilation fails. |
B. | "odd" will always be output. |
C. | "even" will always be output. |
D. | "odd" will be output for odd values of x, and "even" for even values. |
Answer» B. "odd" will always be output. | |
52. |
public void foo( boolean a, boolean b) { if( a ) { System.out.println("A"); /* Line 5 */ } else if(a && b) /* Line 7 */ { System.out.println( "A && B"); } else /* Line 11 */ { if ( !b ) { System.out.println( "notB") ; } else { System.out.println( "ELSE" ) ; } } } |
A. | If a is true and b is true then the output is "A && B" |
B. | If a is true and b is false then the output is "notB" |
C. | If a is false and b is true then the output is "ELSE" |
D. | If a is false and b is false then the output is "ELSE" |
Answer» D. If a is false and b is false then the output is "ELSE" | |