exam questions

Exam 1z0-808 All Questions

View all questions & answers for the 1z0-808 exam

Exam 1z0-808 topic 1 question 193 discussion

Actual exam question from Oracle's 1z0-808
Question #: 193
Topic #: 1
[All 1z0-808 Questions]

Given the class definitions:
class C1 {}
class C2 extends C1 {}
class C3 extends C2 {}
and the code fragment:
16. C1 obj1 = (C1) new C2();
17. C2 obj2 = (C2) new C3();
18. C2 obj3 = (C2) new C1();
19. C3 obj4 = (C3) obj2;
Which line throws ClassCastException?

  • A. line 18
  • B. line 17
  • C. line 19
  • D. line 16
Show Suggested Answer Hide Answer
Suggested Answer: A 🗳️

Comments

Chosen Answer:
This is a voting comment (?). It is better to Upvote an existing comment if you don't have anything to add.
Switch to a voting comment New
Sudhakar_Senthilkumar
1 week, 6 days ago
Selected Answer: A
Answer A - Line Number 18 will throw ClassCast Exception
upvoted 1 times
...
MPignaProTech
2 months, 2 weeks ago
Selected Answer: A
Answer is A
upvoted 1 times
...
UAK94
2 years, 3 months ago
class CC1 { } class CC2 extends CC1 { } public class CC3 extends CC2 { public static void main(String[] args) { CC1 obj1 = (CC1) new CC2(); CC2 obj2 = (CC2) new CC3(); CC2 obj3 = (CC2) new CC1(); // ClassCastException CC3 obj4 = (CC3) obj2; } } /* Exception in thread "main" java.lang.ClassCastException: class questions.CC1 cannot be cast to class questions.CC2 (questions.CC1 and questions.CC2 are in unnamed module of loader 'app') at questions.CC3.main(CC3.java:18) */ Answer is A
upvoted 2 times
...
iSnover
2 years, 3 months ago
Selected Answer: A
The answer is the letter A. C1 cannot access the methods of class C2 because the superclass cannot inherit the methods of the child class.
upvoted 1 times
...
shivkumarx
2 years, 4 months ago
Answer is A: line 18
upvoted 2 times
...
Community vote distribution
A (35%)
C (25%)
B (20%)
Other
Most Voted
A voting comment increases the vote count for the chosen answer by one.

Upvoting a comment with a selected answer will also increase the vote count towards that answer by one. So if you see a comment that you already agree with, you can upvote it instead of posting a new comment.

SaveCancel
Loading ...
exam
Someone Bought Contributor Access for:
SY0-701
London, 1 minute ago