Question Paper C++
Question Paper C++
1
class Test
{
int x;
};
int main()
{
Test t;
cout << t.x;
return 0;
}
Q.2
#include <iostream>
class Test
{
public:
int i;
void get();
};
void Test::get()
{
cout << "Enter the value of i: ";
cin >> i;
}
Test t; // Global object
int main()
{
Test t; // local object
t.get();
cout << "value of i in local t: "<<t.i<<'n';
::t.get();
cout << "value of i in global t: "<<::t.i<<'n';
return 0;
}
A. Compiler Error: Cannot have two objects with same class name
B. Compiler Error in Line "::t.get();"
C. Compiles and runs fine
Q.3 A member function can always access the data in __________ , (in C++).
Q.5 It is possible to define a class within a class termed as nested class. There are _____ types of
nested classes.
A. 2 B. 3 C. 4 D. 5
Q. 6 When one object reference variable is assigned to another object reference variable then
Q.13 Which of the following can access private data members or member functions of a class?
Q. 15 Which of the following is the only technical difference between structures and classes in
C++?
A. Member function and data are by default protected in structures but private in classes.
B. Member function and data are by default private in structures but public in classes.
C. Member function and data are by default public in structures but private in classes.
D. Member function and data are by default public in structures but protected in classes.