Smart pascal source code
{
Demo: Object Orientated Programming (OOP)
}
type
AClass = class
s, t: string;
procedure P(param: string); virtual;
function Q: string;
end;
type
BClass = class(AClass)
u, v: string;
procedure P(param: string); override;
function Q: string;
end;
procedure AClass.P;
begin
WriteLn('AClass.P(' + param + ')');
end;
function AClass.Q: string;
begin
Result := 'AClass.Q: Static method';
end;
procedure BClass.P;
begin
WriteLn('BClass.P(' + param + ')');
inherited P(param);
end;
function BClass.Q: string;
begin
Result := 'BClass.Q: Static method';
inherited P('inh');
end;
var o: AClass;
o := BClass.Create;
WriteLn('--- Virtual methods');
o.P('Hello World!');
BClass(o).P('Hello World!');
WriteLn('');
WriteLn('--- Static methods');
WriteLn(o.Q);
WriteLn(BClass(o).Q);
{<<< RESULT - CONSOLE LOG >>>
-----------------------------
--- Virtual methods
BClass.P(Hello World!)
AClass.P(Hello World!)
BClass.P(Hello World!)
AClass.P(Hello World!)
--- Static methods
AClass.Q: Static method
AClass.P(inh)
BClass.Q: Static method
-----------------------------
{<<<<<<<<< THE END >>>>>>>>>}