|
-
Nov 9th, 2006, 06:26 PM
#1
Thread Starter
Admodistrator
Extends?
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)?
-
Nov 10th, 2006, 04:28 AM
#2
Re: Extends?
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.
-
Nov 10th, 2006, 06:04 AM
#3
Addicted Member
Re: Extends?
 Originally Posted by DeadEyes
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.
#Appreciate others by rating good posts !!
#The Software Peter Principle is in operation when unwise developers "improve" and "generalize" the software until they themselves can no longer understand it, then the project slowly dies.
#People who are still ignorant of their ignorance are dangerous.
-
Nov 10th, 2006, 08:40 AM
#4
Fanatic Member
Re: Extends?
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 In 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:
Super(parameters here...)
-
Nov 10th, 2006, 07:12 PM
#5
Thread Starter
Admodistrator
Re: Extends?
Ah its just inheritence?! I didnt make the connection..
Thanks I will rep you all
-
Nov 10th, 2006, 07:51 PM
#6
Frenzied Member
Re: Extends?
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.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|