Class and inheritance
From the base class "Car", we can inherit other
classes that use its methods, and make instances either of "Car" or
the subclasses.
class Car `
this is a base class
int power = 850
int getPower() return
power
text color(int
c)
text tc = "other"
if c
= 1: tc =
"blue"
= 2: tc = "green"
= 4: tc = "red"
/if
return "color is
" + tc
/class
class FormulaOne is
Car ` FormulaOne is a kind of Car
int speed
int getSpeed()
speed = getPower() * 2 /
4
return speed
/class
FormulaOne f1 //
instance of FormulaOne
print f1.power //
attribute of the superclass
print f1.getPower() //
method of the superclass
print f1.getSpeed() //
method of the class itself
print FormulaOne.color(4)
// static method of the superclass (Car.color() works also).