You are on page 1of 8

C++ Complex Question Set

1. Statement I : All the non-private members of the base class can be accessed
from the derived class as if they were members of the derived class.

Statement II : The protected data members can be accessed in the same class
or in its derived class.

1. Both are true


2. Both are false
3. Statement I is true, statement II is false
4. Statement I is false, statement II is true.

2. ______ the ability of a generalized request (message) to produce different results


based on the object that it is sent to.

1. Inheritance
2. Abstraction
3. Polymorphism
4. Encapsulation

3. What happens when a pointer is deleted twice?


1. It can abort the program
2. It can cause a failure
3. It can cause an error
4. It can cause a trap

4. The statement fwrite ( (char*)&objl, sizeof(objl),1,fl);

1. writes the member functions of objl to fl


2. writes the data in objl to fl
3. writes the member functions and me data of obj 1 to fl
4. writes the address of objl to fl
5. class derived: public base1, public base2 { } is an example of_________

1. Polymorphic inheritance
2. Multilevel inheritance
3. Single Inheritance
4. Multiple inheritance

6. What is the difference between overloaded functions and overridden functions?

1. Overloading is a dynamic or run-time binding and Overriding is static


Or compile- time binding.
2. Redefining a function in a friend class is called function overriding
while Redefining a function in a derived class is called a
overloaded function
3. Overloading is a static or compile-time binding and Overriding is
dynamic or run-time binding
4. Redefining a function in a friend class is called function overloading while
Redefining a function in a derived class is called as overridden fucnion.

7. Which of the following is illegal:

1. template <class T> func(T x) {}


2. template <class T> class myObject {};
3. template <class T> class myObj { template <class R> void memFunc()
{} };
4. none of above

8. Which of the following operators below allow defining the member functions of a
class outside the class?

1. ::

2. ?

3. :?

4. %
9. The return value of the following code is

Class1& test(Class1 obj)


{
Class1 *ptr = new Class1();
.........
return ptr;
}

1. object of Class1
2. reference to ptr
3. reference of Class1
4. object pointed by ptr

10. EMP *eptr = new EMP[5]; call show method for employee having index 3.

1. (*eptr+3).shoe();
2. eptr[3].show()
3. Both 1 & 2
4. (eptr+3)->show();

11. In Complex class prototype of one function is as follows:

Complex& getObject();
What sould be return statement in function definition ?

1. return *this;
2. retrun this&;
3. return &this;
4. return *&this;

12. State TRUE or FALSE:


Basic to class conversion is possible by providing constructor in destination
class.
1. True
2. False
13.
class Complex
{
private:
int real;
int imag;
public:
Complex();
Complex(int,int);
Complex operator=(Complex&);
};

int main()
{
Complex c1(4,5);
Complex c2(6,9);
Complex c3;

C3 = c1 + c2;
return 0;
}

What is the compiler translation for the statement c3 = c1 + c2?

1. c3 =C1.operator+(c2);
2. c3 = Operator+(c1,c2);
3. c3 = C2.operator+(c1);
4. None of of available option

14. State TRUE or FALSE:


Static members can be accessed without instance of class.

1. True
2. False

15. Which of the following library function below by default aborts the program?

1. Terminate()
2. end()
3. Abort()
4. exit()
16. What is deep copy?

1. A deep copy creates a copy of the dynamically allocated objects too.


2. A deep copy just copies the values of the data as they are.
3. A deep copy creates a copy of the statically allocated objects too.
4. Both b and c above

17. What is the difference between overloaded functions and overridden functions?

1. Overloading is a dynamic or run-time binding and Overriding is static or


compile-time binding.
2. Redefining a function in a friend class is called function overriding while
Redefining a function in a derived class is called a overloaded fucntion.
3. Overloading is a static or compile-time binding and Overriding is dynamic or run-
time binding
4. Redefining a function in a friend class is called function overloading while
Redefining a function in a derived class is called as overridden fucnion.

18. Function templates is alternative for function overloading.

1. True
2. False

19. In Complex class prototype of one function is as follows


Complex& getObject();
What sould be return statement in function definition?

1. return *this;
2. retrun this&;
3. return &this;
4. return *&this;

20. Inline functions are invoked at the time of

1. Run time
2. Compile time
3. Depends on how it is invoked
4. Both b and c above

21. How do we define a constructor?

1. X~() {}

2. X() {}~
3. X() ~{}

4. ~X() {}

22. What is the Difference between struct and class in terms of Access Modifier?

1. By default all the struct members are private while by default class members are
public.
2. By default all the struct members are protected while by default class members
are private.
3. By default all the struct members are public while by default class members are
private.
4. By default all the struct members are public while by default class members are
protected.

23. Vtables is _____________

1. creates a static table per class


2. creates a static table per object
3. creates a dynamic table per class
4. creates a dynamic table per object

24. The output of this program is:

int main ()
{
cout << "Hello World!" return 0;
}

1. Hello World
2. Syntax error
3. 0
4. Hello World!
25. The output of this program is :

int a = 10;

void main()
{
int a = 20;
cout << a << ::a;
}

1. Syntax error
2. 10 20
3. 20 10
4. 20 20

26. When class B is inherited from class A, what is the order in which the constructers
of those classes are called

1. Class A first Class B next


2. Class B first Class A next
3. Class B's only as it is the child class
4. Class A's only as it is the parent class

27. Which of the following is a valid destructor of the class name "Country"

1. int ~Country()
2. void Country()
3. int ~Country(Country obj)
4. void ~Country()

28. How would you read the expression x.y as?

1. member y of object pointed by x


2. member y of object x
3. member x of object y
4. All of the above
29. What is the output of the following code snippet assuming user enters the side as 4?

class square
{
public:
double side1;
double area()
{
return(side1*side1);
}
};

int main(){
double area1=0;
square c1,c2;
cout << "Enter the length of the square" << endl;
cin >> c1.side;
cout << "The area of the square is : " << c1.area1() << endl;
return(0);
}

1. 16
2. Will result in an error
3. 8
4. 12

30. Can inline functions be used to improve performance?

1. Yes
2. No
3. yes, depends on the situation
4. Both a and b

You might also like