exam questions

Exam 1z0-808 All Questions

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

Exam 1z0-808 topic 1 question 177 discussion

Actual exam question from Oracle's 1z0-808
Question #: 177
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: B 🗳️

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
MPignaProTech
2 months, 2 weeks ago
finally the answer is DerivedA DerivedB after test
upvoted 1 times
...
MPignaProTech
2 months, 3 weeks ago
Selected Answer: B
B is the correct answer
upvoted 1 times
...
BelloMio
7 months, 1 week ago
I tested as well after I thought I was going crazy. Correct answer is DerivedA DerivedB 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(); Base b4 = b3; b1 = (Base) b2; b1.test(); b4.test(); } }
upvoted 1 times
...
7df49fb
9 months, 3 weeks ago
DerivedA DerivedB
upvoted 1 times
...
amit_lad88
1 year ago
The options are incorrect. The correct answer is DerivedA DerivedB. tested in a local machine.
upvoted 2 times
...
pbbvr
1 year, 5 months ago
DerivedA DerivedB should be the correct answer. Tested!
upvoted 2 times
...
Ericausdresden
1 year, 5 months ago
I dont understand why the first output isnt Base... why does the cast to Base not work...
upvoted 2 times
...
carloswork
2 years, 1 month ago
Answer is "DerivedA DerivedB". -------------------------------------------------- // 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(); Base b4 = b3; b1 = (Base) b2; b1.test(); b4.test(); } } --------------------------------------------------
upvoted 1 times
...
iSnover
2 years, 3 months ago
Selected Answer: B
This question has no correct alternative as it prints "DerivedA DerivedB". What you have to pay in these questions is to which object the variable is pointing and we see this in the "new DerivedB", so we know that our B1 and B3 even being of the "Base" type they are "DerivedB" objects. the variable B4 is a reference of B3 which is a "DerivedB" object so we know that in the second position of the print it is a "DerivedB", even doing a cast of B2 -> Base the overload always takes the child's method then prints "DerivedA " getting "DerivedA DerivedB". To be honest, I don't know what to mark if this happens in the test, but I would mark the alternative that came closest to the truth, which is alternative B. The only one that came closest to the "b1.test()" method and hit the " b4.test()". If in doubt, follow the code:
upvoted 2 times
iSnover
2 years, 3 months ago
class Base { public void test() { System.out.println("Base "); } } 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(); Base b4 = b3; b1 = (Base) b2; b1.test(); b4.test(); } }
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