What will be printed by the following code?
class Test { int x; public: Test() { x = 0; } ~Test() { cout << "Destructor"; } };
int main() { Test t1, t2; return 0; }
Q.82Easy
Which access specifier should be used when a derived class needs to access a base class member but external classes should not?
Q.83Medium
What is the primary advantage of using virtual functions in a base class?
Q.84Hard
Consider the following code: class A { public: virtual ~A() {} }; class B : public A {}; int main() { A *ptr = new B(); delete ptr; }. What does the virtual destructor ensure?
Q.85Medium
Which of the following is an example of operator overloading as a member function?
Advertisement
Q.86Hard
What is the key difference between shallow copy and deep copy in the context of copy constructors?
Q.87Medium
In which scenario would you use an abstract base class instead of a concrete base class?
Q.88Medium
What will be the output of the following code?
class Base { public: void show() { cout << "Base"; } };
class Derived : public Base { public: void show() { cout << "Derived"; } };
int main() { Base *b = new Derived(); b->show(); }
Q.89Easy
A class member declared as 'private' can be accessed by:
Q.90Easy
Which type of inheritance allows multiple classes to inherit from a single base class?
Q.91Medium
Consider a scenario where a derived class needs to access a base class member that should not be accessible to external code. Which access specifier should be used in the base class?
Q.92Medium
What is the output of the following code?
class A { public: virtual void func() { cout << "A"; } };
class B : public A { public: void func() { cout << "B"; } };
class C : public B { public: void func() { cout << "C"; } };
int main() { A *p = new C(); p->func(); }
Q.93Medium
Which of the following statements about constructors is correct?
Q.94Hard
What problem does the Diamond Problem primarily address in multiple inheritance?
Q.95Easy
A pure virtual function is declared using which syntax in C++?
Q.96Medium
What is the primary use of the 'const' keyword when applied to member functions?
Q.97Medium
Which of the following best describes the concept of method overloading?
Q.98Hard
What will be the output?
class Test { public: static int count; };
int Test::count = 0;
int main() { Test t1, t2; Test::count = 5; cout << t1.count << " " << t2.count; }
Q.99Hard
An abstract class in C++ is one that contains at least one pure virtual function. Which statement about abstract classes is TRUE?
Q.100Medium
In C++, when a derived class overrides a virtual function from a base class, which access specifier must be used to ensure proper polymorphic behavior?