ProgrammingThis forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
Consider the following variable declarations.
Frog bill;
HoverFrog ben;
Now consider the following assignment statements.
bill = new HoverFrog();
//statement 1
ben = new Frog();
//statement 2
Which statement would cause an error? Explain your answer.
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.
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
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.
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.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.