0% found this document useful (0 votes)
24 views3 pages

Object Oriented Techniques 2 - Done

Uploaded by

rpaulionka
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
24 views3 pages

Object Oriented Techniques 2 - Done

Uploaded by

rpaulionka
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 3

938407839.

docx Name: Reinas

1. A sports club keeps details of its members. Each member has a unique membership
number, first name, surname and telephone number recorded. Three classes have been
identified:

Member
JuniorMember
SeniorMember

The classes JuniorMember and SeniorMember are related, by single inheritance, to the
class Member:

a. Draw an inheritance diagram for the given classes. [3]

Member

JuniorMember SeniorMember

b. Programs that use objects of the class Member need to create a new member, edit a
member’s details, delete a member’s details and show a member’s details. No other
form of access is to be allowed.
Complete the definition of the attributes and the procedure new for the Member class.
[2]
Class Member
private memberID

public procedure new(aMemberID, aFirstname, aSurname, aTel)


memberID = aMemberID

endprocedure
...
endclass

c. In object-oriented programming, what is meant by encapsulation? [1]


Encapsulation is when you create a bunch of methods and attributes and usually store
it together which is in a class.

d. (i) What is meant by instantiation of an object? [2]


Instantiation of an object is when you create a new object/variable object.

1
938407839.docx Name: Reinas

(ii) Write a statement to create a new Member object with membership number A456, first
name John, surname Bell, telephone number 07981 345987. [2]

member_1 = Member(“A456”, “John”, “Bell”, “07981 345987”)

2. In an object-oriented computer game there is a class called Crawlers. Two subclasses of


Crawlers are Spiders and Bugs.

a. Draw an inheritance diagram for this. [2]

Crawlers

Spiders bugs

b. For the subclass Spiders suggest:


(i) one attribute [1]
Speed attribute
(ii) one method [1]
ShootWeb()

3. In object-oriented programming, what is meant by polymorphism? [2]

Polymorphism is when there are 2 different classes, usually inheriting from a parent class
but those classes have different methods and or attributes.

4. An object-oriented program stores details of a class Bird and a subclass Seagull,


defined as follows.

Class Bird
public procedure move
system.print("Birds can fly")
endprocedure
endclass

Class Seabird inherits Bird


public procedure move (override)
system.print("Seabirds can fly and swim")
endprocedure
endclass

Two new objects are instantiated with the lines:

2
938407839.docx Name: Reinas

bird1 = new Bird()


bird2 = new Seabird()

a. What will be printed when the following lines are executed?


bird1.move
bird2.move [2]
Birds can fly
Seabirds can fly and swim

b. Explain your answer. [2]

The reason that bird2.move prints “Seabirds can fly and swim” is because that
procedure is a local variable to that class and so it overrides the move procedure from
the parent class as shown in the code.
TOTAL [20]

You might also like