Question 1
What will be the output?
class Test {
int x;
};
int main()
{
Test t;
cout << t.x;
return 0;
}
0
Garbage Value
Compiler Error
None of the Above
Question 2
What does the this pointer in C++ represent?
Pointer to class name
Pointer to current object
Pointer to base class
Pointer to constructor
Question 3
#include<iostream>
using namespace std;
class Test
{
static int x;
int *ptr;
int y;
};
int main()
{
Test t;
cout << sizeof(t) << " ";
cout << sizeof(Test *);
}
Question 4
What is the correct way to dynamically create an object in C++?
ClassName obj = new ClassName();
ClassName *obj = new ClassName();
ClassName obj();
ClassName = new object();
Question 5
Which access specifier allows members to be accessed only within the class?
public
protected
private
none of them
Question 6
When a method in a subclass has the same name and type signatures as a method in the superclass, then the method in the subclass _____ the method in the superclass.
Overloads
Friendships
Inherits
Overrides
Question 8
In C++, when one object's reference variable is assigned to another object's reference variable then
a copy of the object is created.
a copy of the reference is created.
a copy of the reference is not created.
it is illegal to assign one object reference variable to another object reference variable.
Question 9
Question 10
Which of the following is not correct for virtual function in C++ ?
Must be declared in public section of class.
Virtual function can be static.
Virtual function should be accessed using pointers.
Virtual function is defined in base class.
There are 16 questions to complete.