Inheritance

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • outofmymind
    New Member
    • Oct 2006
    • 45

    #1

    Inheritance

    Hi

    Im working on this question, and i dont know if what i tried to solve is right or wrong :s, hope to get some advice from you guys:

    You have an interface Student that declares two methods:
    public String getMasterProgra m()
    public String getMatriculatio nNr().
    A class StudentImplemen tation that implements this interface.
    A class HiWi (paid worker at university) that implements two methods:
    public String getContractNr()
    public String getHoursPerMont h()
    Some students are at the same time HiWis.
    i. Please describe where you would use composition and where inheritance and write down the new class.
    my answer: - Inheritance: is the ability to derive one class from another.
    - composition :where one class has a data member that is an instance of the other class.
    - new class: ?? (Im hoping to get some help with this part :S)

    ii. Write the complete declaration for the class WorkingStudent.
    my answer: -I’ am assuming that WorkingStudent, inherits from HiWi ...and im not sure if what i did below is correct......th erefore:

    Code:
    Class WorkingStudent extends HiWi{ //class body}
    thanks

    outofmymind
  • r035198x
    MVP
    • Sep 2006
    • 13225

    #2
    Originally posted by outofmymind
    Hi

    Im working on this question, and i dont know if what i tried to solve is right or wrong :s, hope to get some advice from you guys:

    You have an interface Student that declares two methods:
    public String getMasterProgra m()
    public String getMatriculatio nNr().
    A class StudentImplemen tation that implements this interface.
    A class HiWi (paid worker at university) that implements two methods:
    public String getContractNr()
    public String getHoursPerMont h()
    Some students are at the same time HiWis.
    i. Please describe where you would use composition and where inheritance and write down the new class.
    my answer: - Inheritance: is the ability to derive one class from another.
    - composition :where one class has a data member that is an instance of the other class.
    - new class: ?? (Im hoping to get some help with this part :S)

    ii. Write the complete declaration for the class WorkingStudent.
    my answer: -I’ am assuming that WorkingStudent, inherits from HiWi ...and im not sure if what i did below is correct......th erefore:

    Code:
    Class WorkingStudent extends HiWi{ //class body}
    thanks

    outofmymind
    Code:
    Class WorkingStudent extends HiWi, implements Student{ //class body}
    For the compsition-Inheritance, have a go at this:
    Business technology, IT news, product reviews and enterprise IT strategies.

    Comment

    Working...