3 Replies - 716 Views - Last Post: 01 April 2012 - 03:20 PM

#1 crappyprogrammerboy  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 8
  • Joined: 09-February 11

Can someone help me simply how class and class inheritance works?

Posted 29 March 2012 - 05:51 PM

I am working on an assignment, and I think I made myself lost thinking too much....

I know a class is an object. It has certain properties. I created 2 derived classes from it, these 2 dervived classes also have properties, but with more properties. From those 2 derivived classes stem 2 more classes.

Long story short... I'm not sure if I'm using public properties, functions correctly.. If the 2 derived classes from the derived class of a class, how do I pass my 3rd derived class to the base class. Properties are set value to variable of a class, but how do i recall the value to the main?... I don't know if anyone can understand what I'm saying, but bassically, I want to get the info from the most derivived class to base class.

Is This A Good Question/Topic? 0
  • +

Replies To: Can someone help me simply how class and class inheritance works?

#2 DimitriV  Icon User is offline

  • Don't try to save yourself… the circle is complete
  • member icon

Reputation: 544
  • View blog
  • Posts: 2,632
  • Joined: 24-July 11

Re: Can someone help me simply how class and class inheritance works?

Posted 29 March 2012 - 06:00 PM

AdamSpeight2008 has a good tutorial on Inheritance - it's sure to help you out!

This post has been edited by DimitriV: 29 March 2012 - 06:01 PM

Was This Post Helpful? 0
  • +
  • -

#3 jon.kiparsky  Icon User is online

  • Pancakes!
  • member icon

Reputation: 5421
  • View blog
  • Posts: 8,710
  • Joined: 19-March 11

Re: Can someone help me simply how class and class inheritance works?

Posted 30 March 2012 - 07:01 AM

Quote

I want to get the info from the most derivived class to base class.



I'm not sure what you mean by this. Classes don't typically contain data, unless you're thinking of static fields, and objects only share information via the methods you write for them.
Can you give me a f'rinstance? What is it you're trying to accomplish here?

Maybe you can do it in terms of the good old Animal hierarchy:

Base class is Animal
Vertebrate and Invertebrate extend Animal
Mammal, Bird, and Reptile extend vertebrate / Insect and Mollusk extend Invertebrate
Human and Squirrel extend Mammal, Whelk extends Mollusk (fill in more species as needed

jon is an instance of Human, and lawrence is an instance of Whelk. (sorry...)


Given that hierarchy, what is it you'd like to be able to do?

This post has been edited by jon.kiparsky: 30 March 2012 - 07:02 AM

Was This Post Helpful? 0
  • +
  • -

#4 macosxnerd101  Icon User is online

  • Self-Trained Economist
  • member icon




Reputation: 9029
  • View blog
  • Posts: 33,490
  • Joined: 27-December 08

Re: Can someone help me simply how class and class inheritance works?

Posted 01 April 2012 - 03:20 PM

*Moved to Software Development*
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1