Need help form Java coders please :)
Quote:
To me, the would both cause an error because they both seem to contradict eachother...but I don't know if I'm correct or not. Any ideas? :) Thanks |
You probably need to think about inheritance, but it's kinda hard to say without more details about the classes.
|
Assuming HoverFrog is a specialization of Frog, I'd say #2 is an illegal assignment. But why do you ask?
|
You can think about it like this; HoverFrog is always a Frog, but a Frog is not neccessarily always a HoverFrog. Whoever gave you this hw assignment should've used Toad and HypnoToad :D
|
It's one of many questions on my assignment for university which was due in on the 6th of december lol.
Still can't figure out the right answer. The information I've given you is the only information I've been given myself. |
What can't you figure out?
All classes (e.g. String) are subclasses Object class => they are Objects. But not each Object is String. You can treat String as Object, but not vice versa. So hoverfrog is frog, but not all frogs are hoverfrogs. I hope you'll understand. |
maybe help,
A boy can become a man, but a man cannot become a boy (at least not literally :) ) boy=new Man(); man=new Boy(); |
Without seeing the the class declaration for HoverFrog, I would say that they could both produce an error. If HoverFrog does not "extend" Frog, they would.
|
All times are GMT -5. The time now is 10:37 PM. |