How does inheritance operate when using the object of the classes? - Delphi
How does inheritance operate when using the object of the classes?
- The inheritance needs a parent and a child class where the child class inherits the property of the parent class.
- Child can have their own functions or inherit functions and properties from the parent class.
- TFootball child class is the base class and inheriting the properties of TBall class of the parents.
- The inheritance method is created like this:
var
beachBall : TBall;
soccerBall : TFootball;
begin
beachBall := TBall.Create(5);
soccerBall := TFootball.Create(5, 12);
beachBall.Kick(10);
soccerBall.Kick(10);
ShowMessageFmt('Beach ball is moving at speed : %d',[beachBall.GetSpeed]);
ShowMessageFmt('Soccer ball is moving at speed : %d',[soccerBall.GetSpeed]);
end;
The output is shown as such:
Beach ball is moving at speed: 12
Soccer ball is moving at speed: 12