Results 1 to 6 of 6

Thread: Extends?

  1. #1

    Thread Starter
    Admodistrator |2eM!x's Avatar
    Join Date
    Jan 2005
    Posts
    3,900

    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)?

  2. #2
    Frenzied Member DeadEyes's Avatar
    Join Date
    Jul 2002
    Posts
    1,196

    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.

  3. #3
    Addicted Member SpS's Avatar
    Join Date
    Jul 2005
    Posts
    201

    Re: Extends?

    Quote 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.

  4. #4
    Fanatic Member x-ice's Avatar
    Join Date
    Mar 2004
    Location
    UK
    Posts
    671

    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
    Code:
    Cat Extends ANIMAL
    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...)

  5. #5

    Thread Starter
    Admodistrator |2eM!x's Avatar
    Join Date
    Jan 2005
    Posts
    3,900

    Re: Extends?

    Ah its just inheritence?! I didnt make the connection..

    Thanks I will rep you all

  6. #6
    Frenzied Member System_Error's Avatar
    Join Date
    Apr 2004
    Posts
    1,111

    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
  •  



Click Here to Expand Forum to Full Width