0% found this document useful (0 votes)
55 views13 pages

CPP MCQ - 2

The document discusses C++ OOPS concepts like references, classes, inheritance, and objects. It provides examples and questions to test understanding of key concepts like how references are stored, initializing references, using references to change referents, declaring classes and class members, access specifiers, inheritance, abstract classes, constructors and destructors, virtual functions, and more.

Uploaded by

monika
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
55 views13 pages

CPP MCQ - 2

The document discusses C++ OOPS concepts like references, classes, inheritance, and objects. It provides examples and questions to test understanding of key concepts like how references are stored, initializing references, using references to change referents, declaring classes and class members, access specifiers, inheritance, abstract classes, constructors and destructors, virtual functions, and more.

Uploaded by

monika
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 13

CPP / OOPS QUESTIONS

1. Which of the following statement is correct?

A. A reference is stored on heap.

B. A reference is stored on stack.

C. A reference is stored in a queue.

D. A reference is stored in a binary tree.

Answer: Option B

2. Which of the following statements is correct?

1. Once a reference variable has been defined to refer to a particular variable it can 2. refer to
any other variable.

A reference is not a constant pointer.

A. Only 1 is correct.

B. Only 2 is correct.

C. Both 1 and 2 are correct.

D. Both 1 and 2 are incorrect.

Answer: Option D

3. Functions can be declared to return a reference type. There are reasons to make such a
declaration/Which of the following reasons are correct?

1.The information being returned is a large enough object that returning a reference is more
efficient than returning a copy.

2. The type of the function must be a R-value.


A. Only 1 is correct.

B. Only 2 is correct.

C. Both 1 and 2 are correct.

D. Both 1 and 2 are incorrect.

Answer: Option C

4. Which of the following statements is correct?

1. Change a reference changes the referent.

2. We can create an array of references.

A. Only 1 is correct.

B. Only 2 is correct.

C. Both 1 and 2 are correct.

D. Both 1 and 2 are incorrect.

Answer: Option A

5. Which of the following statement is correct about the references?

A. A reference must always be initialized within functions.

B. A reference must always be initialized outside all functions.

C. A reference must always be initialized.

D. Both A and C.

Answer: Option C

6. A reference is declared using the _____ symbol.

A. &&
B. &

C. ||

D. !

Answer: Option B

7. Which of the following statement is correct?

A. Once a reference variable has been defined to refer to a particular variable it can refer
to any other variable.

B. A reference is indicated by using && operator.

C. Once a reference variable has been defined to refer to a particular variable it cannot
refer to any other variable.

D. A reference can be declared beforehand and initialized later.

Answer: Option C

8. Which of the following statements is correct?

1. A reference is not a constant pointer.

2. A referenced is automatically de-referenced.

A. Only 1 is correct.

B. Only 2 is correct.

C. Both 1 and 2 are correct.

D. Both 1 and 2 are incorrect.

Answer: Option B

9. Which of the following statements is correct?

1. An array of references is acceptable.


2. We can also create a reference to a reference.

A. Only 1 is correct.

B. Only 2 is correct.

C. Both 1 and 2 are correct.

D. Both 1 and 2 are incorrect.

Answer: Option D

10. Which of the following statement is correct?

A. A referenced has to be de-referenced to access a value.

B. A referenced does not need to be de-referenced to access a value.

C. A referenced has to be double de-referenced to access a value.

D. Whether a reference should be de-referenced or not depends on the type of the


reference.

Answer: Option B

11. Which of the following statements is correct?

1. Once the variable and the reference are linked they are tied together.

2. Once the reference of a variable is declared another reference of that variable is not
allowed.

A. Only 1 is correct.

B. Only 2 is correct.

C. Both 1 and 2 are correct.

D. Both 1 and 2 are incorrect.

Answer: Option A
12. Which of the following statements is correct?

1. We can return a global variable by reference.

2. We cannot return a local variable by reference.

A. Only 1 is correct.

B. Only 2 is correct.

C. Both 1 and 2 are correct.

D. Both 1 and 2 are incorrect.

Answer: Option B

13. Reference is like a _____.

A. Pointer

B. Structure

C. Macro

D. Enum

Answer: Option A

14. Which of the following statement is correct?

A. A reference is a constant pointer.

B. A reference is not a constant pointer.

C. An array of references is acceptable.

D. It is possible to create a reference to a reference.


Answer: Option A

15. Which of the following statement is correct?


A. A reference is declared using * operator.

B. Once a reference variable has been defined to refer to a particular variable it can refer
to any other variable.

C. A reference must always be initialized within classes.

D. A variable can have multiple references.

Answer: Option D

16. Which of the following statement is correct?

A. An array of references is acceptable.

B. Once a reference variable has been defined to refer to a particular variable it can refer
to any other variable.

C. An array of references is not acceptable.

D. Reference is like a structure.

Answer: Option C

17. Which of the following statements is correct?

1. Pointer to a reference and reference to a pointer both are valid.

2. When we use reference, we are actually referring to a referent.

A. Only 1 is correct.

B. Only 2 is correct.

C. Both 1 and 2 are correct.

D. Both 1 and 2 are incorrect.

Answer: Option C

1. What happens when we try to compile the class definition in following code snippet?
class Birds {};

class Peacock : protected Birds {};

A. It will not compile because class body of Birds is not defined.

B. It will not compile because class body of Peacock is not defined.

C. It will not compile because a class cannot be protectedly inherited from other class.

D. It will compile succesfully.

Answer: Option D

2. Which of the following statements is incorrect?

A. Friend keyword can be used in the class to allow access to another class.

B. Friend keyword can be used for a function in the public section of a class.

C. Friend keyword can be used for a function in the private section of a class.

D. Friend keyword can be used on main().

Answer: Option D

3. Which of the following statement is correct regarding destructor of base class?

A. Destructor of base class should always be static.

B. Destructor of base class should always be virtual.

C. Destructor of base class should not be virtual.

D. Destructor of base class should always be private.

Answer: Option B

4. Which of the following two entities (reading from Left to Right) can be connected by the
dot operator?

A. A class member and a class object.

B. A class object and a class.

C. A class and a member of that class.

D. A class object and a member of that class.

Answer: Option D

5. How can we make a class abstract?

A. By making all member functions constant.

B. By making at least one member function as pure virtual function.

C. By declaring it abstract using the static keyword.

D. By declaring it abstract using the virtual keyword.

Answer: Option B

6. Which of the following statements is correct when a class is inherited publicly?

A. Public members of the base class become protected members of derived class.

B. Public members of the base class become private members of derived class.

C. Private members of the base class become protected members of derived class.

D. Public members of the base class become public members of derived class.

Answer: Option D

7. Which of the following statements is correct about the constructors and destructors?

A. Destructors can take arguments but constructors cannot.

B. Constructors can take arguments but destructors cannot.


C. Destructors can be overloaded but constructors cannot be overloaded.

D. Constructors and destructors can both return a value.

Answer: Option B

8. Which of the following access specifies is used in a class definition by default?

A. Protected

B. Public

C. Private

D. Friend

Answer: Option C

9. Which of the following statement is correct with respect to the use of friend keyword
inside a class?

A. A private data member can be declared as a friend.

B. A class may be declared as a friend.

C. An object may be declared as a friend.

D. We can use friend keyword as a class name.

Answer: Option B

10. Which of the following keywords is used to control access to a class member?

A. Default

B. Break

C. Protected

D. Asm
Answer: Option C

11. Which of the following can access private data members or member functions of a class?

A. Any function in the program.

B. All global functions in the program.

C. Any member function of that class.

D. Only public member functions of that class

Answer: Option C

12. Which of the following type of data member can be shared by all instances of its class?

A. Public

B. Inherited

C. Static

D. Friend

Answer: Option C

13. Which of the following also known as an instance of a class?

A. Friend Functions

B. Object

C. Member Functions

D. Member Variables

Answer: Option B

14. Constructor is executed when _____.


A. an object is created

B. an object is used

C. a class is declared

D. an object goes out of scope.

Answer: Option A

15. Which of the following statements about virtual base classes is correct?

A. It is used to provide multiple inheritance.

B. It is used to avoid multiple copies of base class in derived class.

C. It is used to allow multiple copies of base class in a derived class.

D. It allows private members of the base class to be inherited in the derived class.

Answer: Option B

16. How many objects can be created from an abstract class?

A. Zero

B. One

C. Two

D. As many as we want

Answer: Option A

17. What does the class definitions in following code represent?

class Bike

Engine objEng;
};

class Engine

float CC;

};

A. kind of relationship

B. has a relationship

C. Inheritance

D. Both A and B

Answer: Option B

18. Which of the following statements is correct when a class is inherited privately?

A. Public members of the base class become protected members of derived class.

B. Public members of the base class become private members of derived class.

C. Private members of the base class become private members of derived class.

D. Public members of the base class become public members of derived class.

Answer: Option B

19. Which of the following statements is correct?

A. Data items in a class must be private.

B. Both data and functions can be either private or public.

C. Member functions of a class must be private.

D. Constructor of a class cannot be private.

Answer: Option B
20. What does a class hierarchy depict?

A. It shows the relationships between the classes in the form of an organization chart.

B. It describes "has a" relationships.

C. It describes "kind of" relationships.

D. It shows the same relationship as a family tree

Answer: Option C

21. Which of the following can be overloaded?

A. Object

B. Functions

C. Operators

D. Both B and C

Answer: Option D

You might also like