class Pet string name int age void eat() print name + " eats" end eat void makeNoise() print name + " yips" end makeNoise end class class Dog inherits Pet string breed Dog * friend Cat * enemy end class void main() Pet * p = new Pet p.name = "Petty" p.eat() Dog * d = new Dog d.name = "Fido" d.breed = "Pugweiloodle" d.eat() end main ---------------------------- class Pet // other stuff void eat() print name + " eats" end eat void makeNoise() print name + " yips" end makeNoise end class class Cat inherits Pet void makeNoise() print name + " goes miaow" end makeNoise void eat(Budgie * b) print name + " eats " + b.name end eat end class void main() Dog * d = new Dog d.name = "Fido" d.breed = "Pugweiloodle" d.makeNoise() Cat * c = new Cat c.name = "Muffy" c.makeNoise() c.eat() Budgie * b = new Budgie c.eat(b) end main ---------------------------- void main() Pet * p String user = prompt "dog, cat, or budgie?" if (user == "dog") then p = new Dog else if (user == "cat") then p = new Cat else p = new Budgie end if p.name = prompt "what name?" p.age = prompt "how old" p.eat() p.sleep() p.makeNoise() // which method called? p.breed = "mutt" // error, not all Pets have breed p.eat(new Budgie) // error not all Pets eat budgies p.fly() // error not all pets can fly Pet * p2 = new Budgie p2.name = "Mr. Furious" p2.fly() // error even if we KNOW it is pointing at a budgie, we can only do Pet things ---------------------------- // not actually pseudocode, just a design outline // of multiple levels of inheritance class Animal { void eat() void move() void sleep() } class Lizard inherits Animal{ void layEggs() } class Mammal inherits Animal { void gestate() } class Chameleon inherits Lizard { void changeColor() } class Cheetah inherits Mammal { // move faster void move() } class Sloth inherits Mammal { // move slower void move() void hangUpsideDown() } ---------------------------- class Bird int eggs void chirp() print "chirp" end chirp void fly() print "fly by flapping" end fly end Bird class Sparrow inherits Bird void chirp() print "chirp chirp chirp" end chirp end Sparrow class Albatross inherits Bird void fly() print "fly by gliding" end fly end Albatross class Penguin inherits Bird void fly() print "can't fly" end fly void swim() print "glides through the water" end fly end Penguin void main() Bird * birdlist[3] birdlist[0] = new Sparrow birdlist[1] = new Albatross birdlist[2] = new Penguin for(int i = 0; i < birdlist.size; i = i + 1) birdlist[i].chirp() birdlist[i].fly() end for end main