program ideone;
{$mode objfpc}{$H+}
type
Parent = class
class function check: boolean; virtual; abstract;
procedure foo;
end;
Child1 = class(Parent)
class function check: boolean; override;
end;
Child2 = class(Parent)
class function check: boolean; override;
end;
procedure Parent.foo;
begin
check;
end;
class function Child1.check: boolean;
begin
writeln('Child1.check');
Result := True;
end;
class function Child2.check: boolean;
begin
writeln('Child2.check');
Result := True;
end;
var
aclass: class of Parent;
begin
Child1.Create.foo;
Child2.Create.foo;
if random < 0.5 then aclass := Child1 else aclass := Child2;
aclass.check;
end.
cHJvZ3JhbSBpZGVvbmU7Cgp7JG1vZGUgb2JqZnBjfXskSCt9Cgp0eXBlCiBQYXJlbnQgPSBjbGFzcwoJICBjbGFzcyBmdW5jdGlvbiBjaGVjazogYm9vbGVhbjsgdmlydHVhbDsgYWJzdHJhY3Q7CgkgIHByb2NlZHVyZSBmb287CgllbmQ7CgogQ2hpbGQxID0gY2xhc3MoUGFyZW50KQoJICBjbGFzcyBmdW5jdGlvbiBjaGVjazogYm9vbGVhbjsgb3ZlcnJpZGU7CgllbmQ7CgogQ2hpbGQyID0gY2xhc3MoUGFyZW50KQoJICBjbGFzcyBmdW5jdGlvbiBjaGVjazogYm9vbGVhbjsgb3ZlcnJpZGU7CgllbmQ7Cgpwcm9jZWR1cmUgUGFyZW50LmZvbzsKYmVnaW4KICBjaGVjazsKZW5kOwoKIGNsYXNzIGZ1bmN0aW9uIENoaWxkMS5jaGVjazogYm9vbGVhbjsKIGJlZ2luCiAgIHdyaXRlbG4oJ0NoaWxkMS5jaGVjaycpOwogICBSZXN1bHQgOj0gVHJ1ZTsKIGVuZDsKCmNsYXNzIGZ1bmN0aW9uIENoaWxkMi5jaGVjazogYm9vbGVhbjsKYmVnaW4KICB3cml0ZWxuKCdDaGlsZDIuY2hlY2snKTsKICBSZXN1bHQgOj0gVHJ1ZTsKZW5kOwoKdmFyCiAgYWNsYXNzOiBjbGFzcyBvZiBQYXJlbnQ7CmJlZ2luCglDaGlsZDEuQ3JlYXRlLmZvbzsKCUNoaWxkMi5DcmVhdGUuZm9vOwogIGlmIHJhbmRvbSA8IDAuNSB0aGVuIGFjbGFzcyA6PSBDaGlsZDEgZWxzZSBhY2xhc3MgOj0gQ2hpbGQyOwogIGFjbGFzcy5jaGVjazsKZW5kLg==