Home Tutorial Java Scjp Part1 SCJP Module-1 Question-5

 
 

Share on Google+Share on Google+
SCJP Module-1 Question-5
Posted on: July 6, 2010 at 12:00 AM
Advertisement
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.

Advertisement

Related Tags for SCJP Module-1 Question-5:


Follow us on Twitter, or add us on Facebook or Google Plus to keep you updated with the recent trends of Java and other open source platforms.

Posted on: July 6, 2010

Recommend the tutorial

Advertisements Advertisements
 

 

 

DMCA.com