SCJP Module-1 Question-5


 

SCJP Module-1 Question-5

The given program module will help you in understating of some typical java codes and it will also help in preparation for SCJP

The given program module will help you in understating of some typical java codes and it will also help in preparation for SCJP

Given the sample code:

public class RoseindiaSample {
public static void main(String[] args) {
int k=5;
System.out.println(getBoolean()? k=3*k++:k+++ ++k);
}

public static boolean getBoolean(){
if((int)(Math.random()*3)==0)
return false;
else
return true;
}
}

Select the correct sentences.

Answer:

(1) Compilation error
(2) Print 12 on each time of execution
(3) Print random 12 or 15 at each execution.
(4) Print 7 or 9 at each execution.

Explanation:

The above code prints either 12 or 15 on each execution.

Ads