Software Development 2

Q1)
a) Consider two C# classes, mobileRobot and grippingRobot, now we decide to create a third class
mobileGrabber that has the same actions as both our mobileRobot and grippingRobot classes.
Explain why C# (and some other languages) will not allow us let mobileGrabber inherit from both
mobileRobot and grippingRobot.

(3 Marks)

b) C# avoids this issue by allowing classes to inherit from multiple interfaces, explain why this
would solve the above problem if mobileRobot and grippingRobot were intefaces rather than
classes.

(3 Marks)

c) What are the rules concerning classes inheriting from interfaces with regard to the methods that
are declared in the interface ?

(2 Marks)

d) Supposing in the example in part a) mobileRobot is a class and grippingRobot is an interface. If
moveRobot is a method that belongs to mobileRobot and closeGripper is a method that belongs
to grippingRobot what would mobileGrabber have to do if it wanted to use these two methods
(assuming it inherited bot mobileRobot and closeGripper).

(2 Marks)
e) If mobileRobot had a method called switchOnRobot and we decided that the inherited class
needed to implement that method differently how could we do this ? Would we still be able to
inherit from the original class and how would we alter the method ? What is this called in Object
Oriented Programming ?

(3 Marks)

f) In terms of object oriented programming and C# describe the following :
i) What is a class constructor and what is its purpose ?

(2 Marks)

ii) What happens if a class does not have a constructor ?

(2 Marks)

iii) Under what circumstances may a class have more than one constructor ?

(2 Marks)
iv) If a class inherits from a superclass that has multiple constructors which constructors
does in inherit ? Explain why.

(2 Marks)

Page 3 of 9

g) Destructors are very rarely used in C# but are common in C++.
i) Explain what a destructor does.

(1 Mark)

ii) State why destructors are used more in C++ than C#.

(2 Marks)

iii) Give one example of when a programmer may use a destructor in C#.

(1 Mark)

Answer

Study Cred Tutor

4.6 (24k+)
4.6/5

Purchase the answer to view it

×

Hello!

Click one of our contacts below to chat on WhatsApp

× How can I help you?