What is the default access specifier for members of a class in C++?
A. friend
B. protected
C. private
D. public
Select an option to see the answer and solution.
Which keyword is used to make a class inheritable by other classes in C++?
A. virtual
B. inheritable
C. extends
D. base
Select an option to see the answer and solution.
What is the purpose of destructors in C++?
A. To initialize objects of a class
B. To define objects within a class
C. To perform calculations with object data
D. To release resources acquired by the object
Select an option to see the answer and solution.
What will be the output of the following C++ code?
#include<iostream>
using namespace std;
class Base {
public:
Base()
{ cout<<"Constructing Base \n"; }
virtual~Base()
{ cout<<"Destructing Base \n"; }
};
class Derived: public Base {
public:
Derived()
{ cout<<"Constructing Derived \n"; }
~Derived()
{ cout<<"Destructing Derived \n"; }
};
int main(void)
{
Derived *d = new Derived();
Base *b = d;
delete b;
return 0;
}A. Constructing Base
Constructing Derived
Destructing Base
B. Constructing Base
Constructing Derived
Destructing Derived
Destructing Base
C. Constructing Base
Constructing Derived
Destructing Base
Destructing Derived
D. Constructing Derived
Constructing Base
Destructing Base
Destructing Derived
Select an option to see the answer and solution.
Which concept allows you to reuse the written code?
A. Encapsulation
B. Abstraction
C. Inheritance
D. Polymorphism
Select an option to see the answer and solution.
What is virtual inheritance?
A. C++ technique to avoid multiple copies of the base class into children/derived class
B. C++ technique to avoid multiple inheritances of classes
C. C++ technique to enhance multiple inheritance
D. C++ technique to ensure that a private member of the base class can be accessed somehow
Select an option to see the answer and solution.
How structures and classes in C++ differ?
A. In Structures, members are public by default whereas, in Classes, they are private by default
B. In Structures, members are private by default whereas, in Classes, they are public by default
C. Structures by default hide every member whereas classes do not
D. Structures cannot have private members whereas classes can have
Select an option to see the answer and solution.
Which of the following class allows to declare only one object of it?
A. Abstract class
B. Virtual class
C. Singleton class
D. Friend class
Select an option to see the answer and solution.
Which of the following is correct about new and malloc?
i. new is an operator whereas malloc is a function
ii. new calls constructor malloc does not
iii. new returns required pointer whereas malloc returns void pointer and needs to be typecast
A. i and ii
B. ii and iii
C. i and iii
D. i, ii and iii
Select an option to see the answer and solution.
How run-time polymorphisms are implemented in C++?
A. Using Inheritance
B. Using Virtual functions
C. Using Templates
D. Using Inheritance and Virtual functions
Select an option to see the answer and solution.
Out of the following, which is not a member of the class?
A. Static function
B. Friend function
C. Constant function
D. Virtual function
Select an option to see the answer and solution.
What is the correct syntax of declaring array of pointers of integers of size 10 in C++?
A. int arr = new int[10];
B. int **arr = new int*[10];
C. int *arr = new int[10];
D. int *arr = new int*[10];
Select an option to see the answer and solution.
Which of the following explains Polymorphism?
Options are not available for this question.
Select an option to see the answer and solution.
Which of the following feature of OOPs is not used in the following C++ code?
class A
{
int i;
public:
void print(){cout<<"hello"<<i;}
}
class B: public A
{
int j;
public:
void assign(int a){j = a;}
}A. Abstraction
B. Encapsulation
C. Inheritance
D. Polymorphism
Select an option to see the answer and solution.
Why references are different from pointers?
A. A reference cannot be made null
B. A reference cannot be changed once initialized
C. No extra operator is needed for dereferencing of a reference
D. All of the mentioned
Select an option to see the answer and solution.
Which of the following explains the overloading of functions?
A. Virtual polymorphism
B. Transient polymorphism
C. Ad-hoc polymorphism
D. Pseudo polymorphism
Select an option to see the answer and solution.
What is the difference between delete and delete[] in C++?
A. delete is used to delete normal objects whereas delete[] is used to pointer objects
B. delete is a keyword whereas delete[] is an identifier
C. delete is used to delete single object whereas delete[] is used to multiple(array/pointer of) objects
D. delete is syntactically correct but delete[] is wrong and hence will give an error if used in any case
Select an option to see the answer and solution.
Which of the following is correct?
A. Base class pointer object cannot point to a derived class object
B. Derived class pointer object cannot point to a base class object
C. A derived class cannot have pointer objects
D. A base class cannot have pointer objects
Select an option to see the answer and solution.
What is the other name used for functions inside a class?
A. Member variables
B. Member functions
C. Class functions
D. Class variables
Select an option to see the answer and solution.
Which of the following is an abstract data type?
A. int
B. float
C. class
D. string
Select an option to see the answer and solution.