Consider this:
Say (just pretend) you have a objects called CD with the following attributes:
shape
size
capacity
[Actions/Methods]
Spin
Record
Then you would have to implement all of those properties and actions. Now say you wanted an object called DVD with the exact same attributes. Ordinarily, you would have to reimplement all of those attributes, even though shape, size, and Spin are the same.
Using inheritance, you can "inherit" DVD from CD and automatically get all of its attributes; the only ones you would have to re-implement are capacity and Record since they are different.
That's what inheritance does in a nutshell. It allows you to reuse the code of other objects where the code would be exactly the same.
Note: I don't vouch for the technical correctness of my example.
Reputation Points: 975
Solved Threads: 140
Posting Virtuoso
Offline 1,624 posts
since Feb 2007