Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / First Aid / February 2006

Tip: Looking for answers? Try searching our database.

inheritance confusion

Thread view: 
Bigval - 11 Feb 2006 16:10 GMT
Right, in a class structure like this

hardware (superclass) param - String name

cpu (subclass of Hardware) params - String name, boolean intel, boolean
amd, String clockSpeed

Intel (subclass of cpu) params - String name, boolean intel, boolean
amd, boolean isSocket478, boolean isSocket775, boolean isSocket604,
String clockSpeed

Amd (subclass of cpu) params - String name, boolean intel, boolean amd,
boolean isSocket754, boolean isSocket939, boolean isSocket940,boolean
isSocketA, String clockSpeed

in Intel and Amd, in their constructors, i use super(name, intel, amd,
clockSpeed) to pass the params up to the cpu class.

however, if i call the method getSpeed in cpu which returns clockSpeed
from the cpu class and prints it, it outputs null :S

a cpu object is initialised thus:

Cpu cpu1 = new Amd( "cpu1", false, true, true, false, false, false,
"3000");
Cpu cpu2 = new Intel( "cpu2", true, false, true, false, false, "4000");

any thoughts?
John
Stefan Schulz - 11 Feb 2006 16:26 GMT
Are you sure you understood your assigment correctly?

You should look up enums, and also reconsider this seriously flawed
design (will isIntel and isAMD ever be both true? Why can they be,
then? What about a Motorola CPU? ...)
Bigval - 11 Feb 2006 16:37 GMT
In the context of what i am expected to achieve and the time and
resources at my disposal, i am only using a handful of data and am
demostrating theories rather than creating a flawless piece of
software.  I am fully aware of its obvious limitations.
Code is being implemented to throw exceptions should certain booleans
clash.

My current problem is the passing of data from subclass to superclass.
If the speed is defined in Amd, how can it be used in cpu.
John
Ranganath Kini - 11 Feb 2006 18:03 GMT
Please provide some code, its pretty difficult to help u with an answer
without looking at ur code.
Roedy Green - 11 Feb 2006 18:03 GMT
On 11 Feb 2006 08:26:24 -0800, "Stefan Schulz"
<schulz.stefan@gmail.com> wrote, quoted or indirectly quoted someone
who said :

>You should look up enums, and also reconsider this seriously flawed
>design (will isIntel and isAMD ever be both true? Why can they be,
>then? What about a Motorola CPU? ...)
See EnumSet
Signature

Canadian Mind Products, Roedy Green.
http://mindprod.com Java custom programming, consulting and coaching.

Stefan Schulz - 11 Feb 2006 21:36 GMT
Roedy, i know that - i was merely trying to point "Bigval" into the
right direction without giving everything away.
Roedy Green - 12 Feb 2006 04:55 GMT
On 11 Feb 2006 13:36:24 -0800, "Stefan Schulz"
<schulz.stefan@gmail.com> wrote, quoted or indirectly quoted someone
who said :

>Roedy, i know that - i was merely trying to point "Bigval" into the
>right direction without giving everything away.

I don't think naming a class or method is too much babying.  Similarly
pointing someone to canned responses to questions just saves time.

Even though the code snippets and the file i/o and conversion
amanuenses could be considered like Clif Notes for Java, I don't
consider them cheating. It is just smart to use tools available to any
programmer at any time.
Signature

Canadian Mind Products, Roedy Green.
http://mindprod.com Java custom programming, consulting and coaching.

Stefan Schulz - 12 Feb 2006 17:40 GMT
Hmm, seemingly you learn very different from me, then. Usually, a
canned response is just that: A single scenario with no insight into
the hows and whys. If i take a few minutes, think things through, and
do a little research on my own, the solution sticks, and contributes to
an overall understanding. Which saves a lot of time a similar problem
comes up, thus being worth the effort.
Ian Mills - 11 Feb 2006 18:00 GMT
> Right, in a class structure like this
>
[quoted text clipped - 25 lines]
> any thoughts?
> John

Please supply a sample of your code as it is difficult to see the
problem from just your description. The fact you are getting null :S
from the call to getSpeed suggests you have another problem.


Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.