Chapter 58
-
-
- Number of legs
- Colour of paws
- Colour of eyes
- Age
- Name
-
- Shortest side length
- Longest side length
-
- Start date
- End date
- Accomodation price per night
- Owner
-
// how dare you use 3-space indentation class Radio // instance variables private volume private station private switch public procedure new(aVolume, aStation, aSwitch) volume = aVolume station = aStation switch = aSwitch endprocedure public procedure setVolume(aVolume) volume = aVolume endprocedure endclassrobertsRadio = new Radio(0.3, 88.2, false) philipsRadio = new Radio(0.6, 37.4, true)-
squeak class Rodent inherits Animal private colour public procedure new(aName, aPosition, aSize) super.new(aName, aPosition) // shame on the book for getting this wrong! size = aSize endprocedure endclass-
tom.positionincreases by 3 andjerry.positionincreases by 2
Exercises
-
-
- Member
- JuniorMember
- SeniorMember
- Member
class Member private memberNumber private firstname private surname private tel public procedure new(aMemberNumber, aFirstname, aSurname, aTel) memberNumber = aMemberNumber firstname = aFirstname surname = aSurname tel = aTel endprocedure endclass-
Encapsulation is the independence of an object's methods and attributes from all other objects of its class.
-
- Instantiation of an object is where the object is created, with a set of attribute values unique that instance. Only a specific instance of a class can read/write to the attributes of that instance
member = new Member("A456", "John", "Bell", "07981 345987")
-
-
-
- Crawlers
- Spiders
- Bugs
- Crawlers
-
typespin_web
-
-
- The practice of having a programming language interpret an object differently depending on its class, via subclassing and method overriding
-
-
Assuming the procedure call is implied:
Birds can fly Seabirds can fly and swim
Otherwise, nothing.
-
bird1is an instance ofBird. Therefore it usesBird'smoveprocedure - and printsBirds can fly.bird2is an instance ofSeabird.SeabirdinheritsmovefromBird, but then overrides it with its ownmovemethod, which printsSeabirds can fly and swim.
-