Sun Certified Java Developer Question:
Download Questions PDF

Can you explain Given:
5. class Building { }
6. public class Barn extends Building {
7. public static void main(String[] args) {
8. Building build1 = new Building();
9. Barn barn1 = new Barn();
10. Barn barn2 = (Barn) build1;
11. Object obj1 = (Object) build1;
12. String str1 = (String) build1;
13. Building build2 = (Building) barn1;
14. }
15. }
Which is true?
A. If line 10 is removed, the compilation succeeds.
B. If line 11 is removed, the compilation succeeds.
C. If line 12 is removed, the compilation succeeds.
D. If line 13 is removed, the compilation succeeds.
E. More than one line must be removed for compilation to succeed.

Answer:

C: If line 12 is removed, the compilation succeeds.

Download Sun Certification Interview Questions And Answers PDF

Previous QuestionNext Question
Explain What is the result of mounting a file system with thenoatimeoption enabled? A.It enables the UFS logging B.It disables the update of file access times C.It prevents the creation of files larger than 2Gbytes D.It prevents the user from updating the file modification timesExplain Which Man class properly represents the relationship "Man has a best friend who is a Dog"? A. class Man extends Dog { } B. class Man implements Dog { } C. class Man { private BestFriend dog; } D. class Man { private Dog bestFriend; } E. class Man { private Dog<bestFriend>; } F. class Man { private BestFriend<dog>; }