473,322 Members | 1,523 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,322 software developers and data experts.

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 getMasterProgram()
public String getMatriculationNr().
A class StudentImplementation that implements this interface.
A class HiWi (paid worker at university) that implements two methods:
public String getContractNr()
public String getHoursPerMonth()
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......therefore:

Expand|Select|Wrap|Line Numbers
  1. Class WorkingStudent extends HiWi{ //class body}
thanks

outofmymind
Nov 4 '06 #1
1 1396
r035198x
13,262 8TB
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 getMasterProgram()
public String getMatriculationNr().
A class StudentImplementation that implements this interface.
A class HiWi (paid worker at university) that implements two methods:
public String getContractNr()
public String getHoursPerMonth()
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......therefore:

Expand|Select|Wrap|Line Numbers
  1. Class WorkingStudent extends HiWi{ //class body}
thanks

outofmymind
Expand|Select|Wrap|Line Numbers
  1. Class WorkingStudent extends HiWi, implements Student{ //class body}
For the compsition-Inheritance, have a go at this:
http://www.javaworld.com/javaworld/j...echniques.html
Nov 6 '06 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

2
by: AIM | last post by:
Error in msvc in building inheritance.obj to build hello.pyd Hello, I am trying to build the boost 1.31.0 sample extension hello.cpp. I can not compile the file inheritance.cpp because the two...
2
by: Graham Banks | last post by:
Does using multiple inheritance introduce any more performance overhead than single inheritance?
4
by: JKop | last post by:
I'm starting to think that whenever you derive one class from another, that you should use virtual inheritance *all* the time, unless you have an explicit reason not to. I'm even thinking that...
5
by: Morgan Cheng | last post by:
It seems no pattern defined by GoF takes advantage of multiple inheritance. I am wondering if there is a situation where multiple inheritance is a necessary solution. When coding in C++, should...
10
by: davidrubin | last post by:
Structural inheritance (inheriting implementation) is equivalent to composition in that a particular method must either call 'Base::foo' or invoke 'base.foo'. Apparantly, The Literature tells us to...
14
by: Steve Jorgensen | last post by:
Recently, I tried and did a poor job explaining an idea I've had for handling a particular case of implementation inheritance that would be easy and obvious in a fully OOP language, but is not at...
22
by: Matthew Louden | last post by:
I want to know why C# doesnt support multiple inheritance? But why we can inherit multiple interfaces instead? I know this is the rule, but I dont understand why. Can anyone give me some concrete...
45
by: Ben Blank | last post by:
I'm writing a family of classes which all inherit most of their methods and code (including constructors) from a single base class. When attempting to instance one of the derived classes using...
60
by: Shawnk | last post by:
Some Sr. colleges and I have had an on going discussion relative to when and if C# will ever support 'true' multiple inheritance. Relevant to this, I wanted to query the C# community (the...
6
by: Bart Simpson | last post by:
I remember reading on parashift recently, that "Composition is for code reuse, inheritance is for flexibility" see (http://www.parashift.com/c++-faq-lite/smalltalk.html#faq-30.4) This confused...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.