





Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
This page cannot be seen from the preview
Don't miss anything!






1
2
3
4
class C { … public: virtual int foo() { … }} class D :public C { virtual int foo() { … }} class E :public C { virtual int foo() { … }}
int foo(C * obj) { if (obj is a D) ... // code from D::foo() else if (obj is an E) ... // code from E::foo() else ... // code from C::foo() }
5
6
10
class B { public int foo () { return 0; } }
class C extends B { public int foo () { return 1; } }
B obj = new C(); int i = obj.foo (); /* executes C.foo */
11
C * p = new D(); p->foo(42, p)
12
13
14
15
class A { int x; }; class B { int y; public: virtual int foo (int); }; class C : public A, public B { int z; public: virtual int foo (int); virtual void bar (int); };
19
20
int foo (C); int foo (D); C p = new D(); int i = foo(p); // calls foo(D)
21
p.foo(5); p->foo(5);
p foo 5. 6 * 7. someArray at: 1 put: 5. x = 0 ifTrue: [y <- 1] ifFalse: [y <- 2].
22
23
class A { public: virtual int foo () = 0; }; class C : public A { /* ... */ }
24
interface I { int foo (); } class C implements I { /* ... */ }