oop is as



oop is as
Smart pascal source code
{ Demo: Object Orientated Programming (OOP) } type AClass = class function Q: string; end; type BClass = class(AClass) function Q: string; end; type CClass = class function Q: string; end; function AClass.Q: string; begin Result := 'AClass.Q: Static method'; end; function BClass.Q: string; begin Result := 'BClass.Q: Static method'; end; function CClass.Q: string; begin Result := 'CClass.Q: Static method'; end; var objA, objB: AClass; objA := AClass.Create; objB := BClass.Create; if objA is AClass then WriteLn('objA is AClass'); if objA is BClass then WriteLn('objA is BClass'); if objA is CClass then WriteLn('objA is CClass'); if objB is AClass then WriteLn('objB is AClass'); if objB is BClass then WriteLn('objB is BClass'); if objB is CClass then WriteLn('objB is CClass'); WriteLn((objA as AClass).Q); try WriteLn((objA as BClass).Q); except WriteLn('objA isn''t BClass'); end; try WriteLn((objA as CClass).Q); except WriteLn('objA isn''t CClass'); end; WriteLn((objB as AClass).Q); WriteLn((objB as BClass).Q); try WriteLn((objB as CClass).Q); except WriteLn('objB isn''t CClass'); end; {<<< RESULT - CONSOLE LOG >>> ----------------------------- Errors >>>> Warning: Incompatible types: "AClass" and "CClass" [line: 42, column: 9] Warning: Incompatible types: "AClass" and "CClass" [line: 46, column: 9] Result >>>> objA is AClass objB is AClass objB is BClass AClass.Q: Static method objA isn't BClass objA isn't CClass AClass.Q: Static method BClass.Q: Static method objB isn't CClass ----------------------------- {<<<<<<<<< THE END >>>>>>>>>}