Govt. Exams
Entrance Exams
Static members belong to the class, not to individual objects. All objects of the class share the same static member, making it useful for counters, constants, etc.
The 'this' pointer is an implicit pointer that points to the current object. It is automatically available in non-static member functions.
class Base { public: void show() { cout
Without the virtual keyword, static binding occurs. The function called is determined by the pointer type (Base*), not the actual object type. Output is 'Base'.
In C++, the default access specifier for class members is private. For structs, it is public.
Constructors do not have a return type, not even void. They are special member functions that automatically initialize objects when created.
The 'override' keyword (C++11) provides compile-time checking to ensure that a function actually overrides a virtual function from the base class.
A friend function is declared using the 'friend' keyword and can access private and protected members of the class, breaking encapsulation when necessary.
class A { public: virtual void func() { cout
Since func() is virtual and ptr points to a B object, B::func() is called due to dynamic dispatch, printing 'B'.
Memory Polymorphism is not a recognized type of polymorphism in C++. The main types are compile-time (static), runtime (dynamic), and parametric polymorphism.
A destructor is called when an object is destroyed, allowing cleanup of dynamically allocated memory and other resources.