exam questions

Exam 1z0-808 All Questions

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

Exam 1z0-808 topic 1 question 95 discussion

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

Given:

What is the result?

  • A. A B
  • B. A C
  • C. C C
  • D. A ClassCastException is thrown only at line n1.
  • E. A ClassCastException is thrown only at line n2.
Show Suggested Answer Hide Answer
Suggested Answer: E 🗳️

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
iSnover
Highly Voted 2 years, 3 months ago
Selected Answer: E
The right answer is the letter E, class C cannot be B because B extends A and C also extends C, there is no inheritance between C and B because neither of the 2 classes extends the other, generating the exception Class Cast Exception on the line 2 where trying to perform the polymorphism of C -> B. I also tested the code, if you want to test it too it is below: class A { public void test () { System.out.println ("A"); } } class B extends A { public void test () { System.out.println ("B"); } } public class C extends A { public void test () { System.out.println ("C"); } public static void main(String[] args) { A b1 = new A (); A b2 = new C (); b1 = (A) b2; //line n1 A b3 = (B) b2; //line n2 b1.test (); b3.test (); } }
upvoted 7 times
...
MPignaProTech
Most Recent 3 months ago
Selected Answer: E
Down casting is forbiden
upvoted 1 times
...
MPignaProTech
3 months ago
Selected Answer: E
down casting is forbiden. E is the correct answer
upvoted 1 times
...
7df49fb
10 months ago
E : B is subclass of A, C is subclass of A, we can cast from one to another via implicite and explicite casting C is not a subclass of B, so we can't cast from C to B and vice versal
upvoted 1 times
...
somrita90
1 year, 4 months ago
Answer is C C tested
upvoted 1 times
...
Sreeni_A
1 year, 5 months ago
Answer is E
upvoted 1 times
...
IbrahimAlnutayfi
1 year, 6 months ago
The answer is E
upvoted 1 times
...
eilla
2 years, 1 month ago
Answer is E as C cannot be cast to B as it does not inherit from that class
upvoted 2 times
...
carloswork
2 years, 2 months ago
Selected Answer: E
Tested as below, with iSnover's source code, answer is E.
upvoted 1 times
...
kkaayyyy
2 years, 3 months ago
Answer is E. It shows the error as " Exception in thread "main" java.lang.ClassCastException: class p1.Acc cannot be cast to class p1.B (p1.Acc and p1.B are in module KK.java of loader 'app') at KK.java/p1.Acc.main(Acc.java:20) "
upvoted 1 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