Tested. Answer is D.
To test:
class Bird {
public void fly() {
System.out.print("Fly.");
}
}
class Peacock extends Bird {
public void dance() {
System.out.print("Dance.");
}
}
public class Test {
public static void main(String[] args) {
Bird b = new Peacock (); Peacock p = (Peacock) b;
p.fly();
p.dance();
}
}
The correct answer is the letter B, you need to create an object B and then do a casting for it, making the same be able to access the method of the child class.
You're are wrong. Correct answer is D. Option B is not how downcasting works. Option D is the textbook definition of downcating. With option our object type is peacock and class type of reference variable is also Peacock and peacock is a child class. Child class peacock can access it's method as well as Parent class Bird method.
Correct answer is D. For option B there is ClassCastException as class Bird cannot be casted to class Peacock
upvoted 4 times
...
This section is not available anymore. Please use the main Exam Page.1z0-808 Exam Questions
Log in to ExamTopics
Sign in:
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.
MPignaProTech
6 months, 2 weeks agoBelloMio
11 months, 1 week ago7df49fb
1 year, 1 month agoDriftKing
1 year, 8 months agoamigo31
2 years, 5 months agocarloswork
2 years, 6 months agoUAK94
2 years, 6 months agoiSnover
2 years, 7 months agoDriftKing
1 year, 8 months agoDriftKing
1 year, 8 months agoalex_au
2 years, 7 months ago