exam questions

Exam 1z0-808 All Questions

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

Exam 1z0-808 topic 1 question 44 discussion

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

Given:

What is the result?

  • A. Base DerivedA
  • B. Base DerivedB
  • C. DerivedB DerivedB
  • D. DerivedB DerivedA
  • E. A ClassCastException is thrown at runtime.
Show Suggested Answer Hide Answer
Suggested Answer: C 🗳️

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
v323rs
Highly Voted 4 years, 11 months ago
DerivedB DerivedB
upvoted 13 times
...
walkietalkie
Highly Voted 4 years, 7 months ago
tested Correct : DerivedB DerivedB
upvoted 7 times
...
vic88
Most Recent 1 week, 5 days ago
Selected Answer: C
answer is C
upvoted 1 times
...
Kolodets
1 year, 7 months ago
Polymorphy: the most specific available overridden method for the object type is used => take from the bottom (lowest Child) DerivedB DerivedB
upvoted 2 times
...
Vicky_65
1 year, 8 months ago
Selected Answer: C
Answer is C
upvoted 1 times
...
odzio33
1 year, 11 months ago
public class DerivedB extends DerivedA{ public void test(){ System.out.println("DerivedB "); } public static void main(String[] args){ Base b1 = new DerivedB(); Base b2 = new DerivedA(); Base b3 = new DerivedB(); b1.test(); b2.test(); b3.test(); b1= (Base) b3; b1.test(); Base b4 = (DerivedA) b3; b4.test(); b1.test(); } }
upvoted 1 times
...
akbiyik
2 years ago
Casting doesn't change the object itself. In inheritance, we create new classes that inherit features of the superclass while polymorphism decides what form of method to execute. Answer is C DerivedB DerivedB
upvoted 2 times
...
carloswork
2 years ago
Selected Answer: C
Answer is C. -------------------------------- //Base.java public class Base { public void test() { System.out.println("Base "); } } ---------------- //DerivedA.java class DerivedA extends Base { public void test() { System.out.println("DerivedA "); } } ---------------- // DerivedB.java class DerivedB extends DerivedA { public void test() { System.out.println("DerivedB "); } public static void main(String[] args) { Base b1 = new DerivedB(); Base b2 = new DerivedA(); Base b3 = new DerivedB(); b1 = (Base) b3; Base b4 = (DerivedA) b3; b1.test(); b4.test(); } } --------------------------------
upvoted 1 times
...
hhuo
2 years, 1 month ago
Selected Answer: C
DerivedB DerivedB
upvoted 1 times
...
tapsshore
2 years, 4 months ago
answer is DerivedB DerivedB i have tested in IDE
upvoted 1 times
...
juipeng
2 years, 6 months ago
class Base { public void test() { System.out.println("Base "); } } public class DerivedA extends Base{ public void test() { System.out.println("DerivedA "); } } public class DerivedB extends DerivedA{ public void test() { System.out.println("DerivedB "); } public static void main(String[] args) { Base b1 = new DerivedB(); Base b2 = new DerivedA(); Base b3 = new DerivedB(); b1 = (Base)b3; Base b4 = (DerivedA)b3; b1.test(); b4.test(); } }
upvoted 2 times
...
Murad22
2 years, 7 months ago
the answer is B, because of the test method is overrided, and the call happened in subclass, right ??
upvoted 1 times
...
hitdaroad
2 years, 7 months ago
I just tested and it's E. You cannot cast a DerivedB instance to DerivedA
upvoted 1 times
hitdaroad
2 years, 7 months ago
im sorry I read it wrong, I thought derivedB extended Base
upvoted 1 times
...
...
XalaGyan
2 years, 10 months ago
Selected Answer: C
C is correct
upvoted 2 times
...
CosminCof
3 years, 2 months ago
The correct answer is E, class cast exception
upvoted 1 times
...
letmein2
5 years, 6 months ago
Correct. There is no problem with the casting (implicit upcasting is actually optional).
upvoted 6 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