Tutorial by Examples

Static members have class scope as opposed to object scope C++ Example // define in header class Singleton { public: static Singleton *getInstance(); private: Singleton() {} static Singleton *instance; }; // initialize in .cpp Singleton* Singleton::instance = 0...
Defined within Another Class C++ Nested Class[ref] (needs a reference to enclosing class) class Outer { class Inner { public: Inner(Outer* o) :outer(o) {} private: Outer* outer; }; }; Java [non-static] Nested Class (aka Inner Class or Member Class...
Many argue that Java is ONLY pass-by-value, but it's more nuanced than that. Compare the following C++ and Java examples to see the many flavors of pass-by-value (aka copy) and pass-by-reference (aka alias). C++ Example (complete code) // passes a COPY of the object static void passByCopy(Pa...
C++ & Java are both object-oriented languages, thus the following diagram applies to both.
Beware of using "downcasting" - Downcasting is casting down the inheritance hierarchy from a base class to a subclass (i.e. opposite of polymorphism). In general, use polymorphism & overriding instead of instanceof & downcasting. C++ Example // explicit type case required Child ...
Abstract Method declared without an implementation C++ pure virtual method virtual void eat(void) = 0; Java abstract method abstract void draw(); Abstract Class cannot be instantiated C++ cannot be instantiated; has at least 1 pure virtual method class AB {public: virtual void f() = ...

Page 1 of 1