, . , . , . , . - - . . , , Java . . C++:
class Person { private: -- int number; -- public: -- char name[10]; -- protected: -- int age; -- float height; -- }; |
- . . A B, A B, . ,
class B { friend class A; -- . }; |
A B. B, , . ,
class B { friend A::methodX; -- }; |
, , . . , C++ . Java, , interface . Java C# , , , -. , ( ). C++ . C++:
class Interchanger { virtual int get ()=0; virtual void put ()=0; }; |
- , . , , . :
|
|
- .
- . , if switch-, .
:
if (methodA()<>ERROR) { if (methodB()<>ERROR) { } else {} else {} |
. : .
: , , . try. , catch , , , finally. . , . throw. ++:
try { methodA(); methodB(); } catch (Error e) {} finally {} |
, , . , try ( ).
. : ( throw, , , ). - , . , ; , . :
, , , , , .
.
, , , .
|
|
, . , -, -. . . .
- throw, . . , , . .
, , .
, , . , . , .
, . . . , C++:
try { -- X int x, y, z; try { -- Y int a, b, c; -- P } catch () {} } catch () {} |
P :
, , , ( ). ( , , ). , . , , , . , , . , .
- : . . ( , ), . , . , . , , , . :
|
|
template <class A, class B> class Entity { A var1; B var2; }; |
, , , , . , , e Entity int float :
Entity<int, float> e; |
, . . , , . , Entity :
: . , , , . , . . , C++ :
template <class T> T Mid (T x, T y) { return (x+y)/2; } |
:
float x=Mid<float> (a, b); |
, , :