Share on Google+Share on Google+

SCJP Module-1 Question-12

Advertisement
The given program check your core java concepts and helps for SCJP examination.

Given a sample code:

1 public class Sample1 {
2 public static void main(String[] args) {
3 for (int i = 0; i < 2; i++) {
4 System.out.println(getValue(101));
}}

5 public static int getValue(int i) {
6 return (short) (Math.random() * i);
}}

What will be the result of above code ?

(1) Compilation fails because of an error at line 4
(2) Compilation fails because of an error at line 5
(3) Compilation fails because of an error at line 6
(4) Compile and run successfully with with two random number as output

Answer

(4)

Advertisements

Posted on: July 7, 2010 If you enjoyed this post then why not add us on Google+? Add us to your Circles

Share this Tutorial 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.