{[ promptMessage ]}

Bookmark it

{[ promptMessage ]}

# OOP1 - int y public D(int a,int b:C(a{y=b int getY return y...

This preview shows pages 1–4. Sign up to view the full content.

CSC 4101: Programming Languages 1 1 Object-Oriented Programming Textbook Chapter 9 Objects struct S { int x; float y; }; S a; a.x = 42; a.y = 3.14; S * p = &a; S * q = new S; int i = p->x; int j = q->x; a: x = 42 y = 3.14 p: q: 2 Methods struct S { int x; float y; int getX() { return x; } }; S * p = new S; p->x = 42; p->y = 3.14; int i = p->getX(); 3

This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document
CSC 4101: Programming Languages 2 Constructors struct S { int x; float y; S(int a, float b) { x = a; y = b; } int getX() { return x; } }; S * p = new S(42, 3.14); int i = p->getX(); 4 Visibility Specifiers struct S { private: int x; float y; public: S(int a, float b) { x = a; y = b; } int getX() { return x; } }; S * p = new S(42, 3.14); int i = p->getX(); int j = p->x; 5 struct vs. class struct S { private: = ... }; class S { public: = ... }; class S { ... }; struct S { ... }; 6