0% found this document useful (0 votes)
145 views7 pages

Inheritance and Dynamic Memory Management: MCQ Unit-4 CSE202

The document contains 10 multiple choice questions about inheritance and dynamic memory management in C++. The questions cover topics like which members can be inherited, valid destructor syntax, constructor overloading, deriving one class from another, static vs non-static class members, and virtual functions. For each question there are 4 possible answers listed along with the correct answer.

Uploaded by

Karthik Sîngh
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)
145 views7 pages

Inheritance and Dynamic Memory Management: MCQ Unit-4 CSE202

The document contains 10 multiple choice questions about inheritance and dynamic memory management in C++. The questions cover topics like which members can be inherited, valid destructor syntax, constructor overloading, deriving one class from another, static vs non-static class members, and virtual functions. For each question there are 4 possible answers listed along with the correct answer.

Uploaded by

Karthik Sîngh
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/ 7

MCQ

Inheritance and Dynamic Memory Management


Unit-4 CSE202

Que.1. Which of the following cannot be inherited from the base class?
A. Constructor
B. Friend
C. Both a and b cannot be inherited
D. Both a and b can be inherited

Right Answer: C

Que.2. class derived: public base1, public base2{} is an example of


A. Polymorphic inheritance
B. Multilevel inheritance
C. Hierarchical inheritance
D. Multiple inheritance

Right Answer: D

Que.3. Which of the following is a valid destructor of the class name “Country”
A. int ~Country()
B. void Country()
C. int ~Country(Contry obj)
D. void ~Country()

Right Answer: D

Que.4. class Example {


Public: int a,b,c;
Example () {a=b=c=1 ;} // Constructor 1
Example (int a) {a=a; b=c=1;} // Constructor 2
Example (int a, int b) {a=a; b=b; c=c;} // Constructor 3
Example (int a, int b, int c){ a=a; b=b; c=c;} // Constructor 4 }
In the above example of constructor overloading, the following statement will call which
constructor
Example obj = new Example (1,2,3.3)
A. Constructor 2
B. Constructor 4
C. Constructor 1
D. Type mismatch error

Right Answer: B

Que.5. If a class x needs to be derived from a class y, which of the following ways is
Correct to do so?
A. Class x: public y
B. Class y : public x
C. Class x derives public y
D. Class y derives public x
Right Answer: A

Que.6. A class cannot inherit members from more than one class
A. True
B. False

Right Answer: B

Que.7. Which of the following is not true about preprocessor directives

A. They begin with a hash symbol


B. They are processed by a preprocessor
C. They from an integral part of the code
D. They have to end with a semi colon

Right Answer: D

Que.8. The output of this program is


int
main () {
cont<<”Hello World”
return 0;
}
A. Hello World
B. Syntax error
C. 0
D. Hello World!

Right Answer: B

Que.9. Can inline functions be used to improve performance?


A. Yes
B. No
C. Yes, depends on the situation
D. Both a and b

Right Answer: D

Que.10. If a member needs to have uniQue value for all the objects of that same class, declare
the member as
A. Global variable outside class
B. Local variable inside constructor
C. Static variable inside class
D. Dynamic variable inside class

Right Answer: B

Que.1. int a = 10;

Void main()

int a = 20;

count <<a<<::a;

The output of this program is

A. Syntax error

B. 10 20

C. 20 10

D. 20 20

Right Answer: C

Que.2. Write the output of the following;

char *mychar; // points to memory location 1000

short *mychart; // points to memory location 2000

long *mylong// points to memory location 3000

mychar++;

++myshort;

mylong++;

count<<mychar<<myshort<<mylong;

A. 1001 2001 3001

B. 1001 2002 3004


C. 1001 2001 3002

D. 1001 2002 3004

Right Answer: D

Que.3. Which one of the following is not a fundamental data type in C++

A. float

B. string

C. Int

D. Wchar_t

Right Answer: B

Que.4. What is the output of the following code snippet assuming user enters the side

as 4?

class square

Public:

double side1;

double area() {

double (side1*side1);

};

int main(){

double area1=0;

squre c1,c2;

count<<”Enter the length of the squre”<<endl;


cin>>c1.side;

cout<<”The area of the square is : “<<c1.area1()<<endl;

return (0);

A. 16

B. Will result in an error

C. 8

D. 12

Right Answer: B

Que.5. When class B is inherited from class A, what is the order in which the

constructor of those classes are called

A. Class A first Class B next

B. Class B first Class A next

C. Class B’s only as it is the child class

D. Class A’s only as it is the parent class

Right Answer: A

Que.6. Which one of the following is not a valid reserved keyword in C++

A. Explicit

B. Public

C. Implicit

D. Private

Right Answer: C
Que.7. Value of a in a = (b = 5, b + 5); is

A. Junk value

B. Syntax error

C. 5

D. 10

Right Answer: D

Que.8. A null pointer is nothing but a void pointer pointing to nowhere.

A. True

B. False

Right Answer: B

Que.9. Which of the following members do get inherited but become private members

in child class

A. Public

B. Private

C. Protected

D. All of the above

Right Answer: C

Que.10. What is a virtual member?

A. A member of a friend class that can be redefined in its derived classes

B. A member of a virtual class that cannot be redefined in its derived classes

C. A member of a static class that can be redefined in its derived classes


D. A member of a class that can be redefined in its classes

Right Answer: D

You might also like