Click to See Complete Forum and Search --> : Extends?
|2eM!x
Nov 9th, 2006, 06:26 PM
In class we have used the word extends lately, for graphics programming etc..
Im just wondering, what does it do and in what cases do i need to use it? Is it only when I need to access some part of an already made class (graphics etc)?
DeadEyes
Nov 10th, 2006, 04:28 AM
You use the extends keyword when you want your class to inherit from another class. Inheritance is a fundamental part of OO programming and quite hard to explain short post, I suggest doing some googling.
SpS
Nov 10th, 2006, 06:04 AM
You use the extends keyword when you want your class to inherit from another class.
or if you want to extend an interface to create another interface.
x-ice
Nov 10th, 2006, 08:40 AM
You would use it in this situation:
You have the classes ANIMAL, Cat, Dog, Monkey
ANIMAL would contain all the info that is common to all the animals you have.
E.g. Cat, Dog and Monkey would all have laysEggs = False
Then the cat, dog and monkey classes would all contain different info specific to that animal.
So instead of repeating data you would have a super class of Animal, and all other classes (that are animals) would extend that.
So you would do Cat Extends ANIMALIn the constructor of Cat you must call the constructor of the super class. I haven't coded in Java for a while now, but i think you do it like this. Super(parameters here...)
|2eM!x
Nov 10th, 2006, 07:12 PM
Ah its just inheritence?! I didnt make the connection..
Thanks I will rep you all
System_Error
Nov 10th, 2006, 07:51 PM
Yep, it's inheritance. You extend classes and implement interfaces (for the most part). Remember, you cannot inherit (extend) more than one class, but you can implement more than one interface.
vbforums.com
Copyright Internet.com Inc., All Rights Reserved.