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

 
 

Share on Google+Share on Google+
SCJP Module-1 Question-18
Posted on: July 8, 2010 at 12:00 AM
Advertisement
This program will test your knowledge of Object class in Java and it also very useful for SCJP examination.

Given a sample code:

1 public class Sample {
2 public static void main(String args[]) {
3    Object obj = new String[] { "1", "2", "3", "4", "5" };
    {
4        for (String str : (String[]) obj)
5        System.out.print(str);
    }
}}

What will be the result of above code ?

(1)    Compilation error at line number 3
(2)    Compilation error at line number 4  
(3)    Prints 12345
(4)    Raise runtime exception 

Answer:

(3)

Advertisement

Related Tags for SCJP Module-1 Question-18:


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 8, 2010

Recommend the tutorial

Advertisements Advertisements
 

 

 

DMCA.com