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)?
Printable View
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)?
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.
or if you want to extend an interface to create another interface.Quote:
Originally Posted by DeadEyes
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 doIn 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.Code:Cat Extends ANIMAL
Code:Super(parameters here...)
Ah its just inheritence?! I didnt make the connection..
Thanks I will rep you all
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.