LinuxQuestions.org
Latest LQ Deal: Latest LQ Deals
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 12-17-2007, 11:26 AM   #1
Xodiac
LQ Newbie
 
Registered: Dec 2007
Posts: 2

Rep: Reputation: 0
Need help form Java coders please :)


Quote:
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.

Any ideas?
Thanks
 
Old 12-17-2007, 11:59 AM   #2
Nylex
LQ Addict
 
Registered: Jul 2003
Location: London, UK
Distribution: Slackware
Posts: 7,464

Rep: Reputation: Disabled
You probably need to think about inheritance, but it's kinda hard to say without more details about the classes.
 
Old 12-17-2007, 12:45 PM   #3
peart
Member
 
Registered: Nov 2003
Distribution: Arch
Posts: 31

Rep: Reputation: 16
Assuming HoverFrog is a specialization of Frog, I'd say #2 is an illegal assignment. But why do you ask?
 
Old 12-17-2007, 12:50 PM   #4
95se
Member
 
Registered: Apr 2002
Location: Windsor, ON, CA
Distribution: Ubuntu
Posts: 740

Rep: Reputation: 32
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
 
Old 12-17-2007, 12:53 PM   #5
Xodiac
LQ Newbie
 
Registered: Dec 2007
Posts: 2

Original Poster
Rep: Reputation: 0
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.
 
Old 12-22-2007, 04:43 AM   #6
Alien_Hominid
Senior Member
 
Registered: Oct 2005
Location: Lithuania
Distribution: Hybrid
Posts: 2,247

Rep: Reputation: 53
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.
 
Old 12-22-2007, 05:19 AM   #7
Looking_Lost
Senior Member
 
Registered: Apr 2003
Location: Eire
Distribution: Slackware 12.0, OpenSuse 10.3
Posts: 1,120

Rep: Reputation: 45
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();
 
Old 12-22-2007, 05:33 AM   #8
jay73
LQ Guru
 
Registered: Nov 2006
Location: Belgium
Distribution: Ubuntu 11.04, Debian testing
Posts: 5,019

Rep: Reputation: 133Reputation: 133
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.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
java: form submission w/ diff submit names? BrianK Programming 1 09-13-2007 06:40 PM
LXer: Sun to coders: Open source Java won't change your life LXer Syndicated Linux News 0 08-16-2006 10:03 PM
(java) BASIC and FORM based auth in the same web app mhiggins Programming 0 10-14-2004 10:07 AM
how do I copy a whoel folder form one directory to another form the command line? zwyrbla Linux - Newbie 8 08-24-2004 06:40 PM
Java coders? AMDPwred Programming 3 12-31-2002 12:22 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 08:26 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration