C++ Data Types and Functions Quiz
C++ Data Types and Functions Quiz
A. 2
B. 4
C. 2 or 4
ANSWER: A
A. array type
B. character type
C. boolean type
D. integer type
ANSWER: A
A. int
B. short
C. void
D. float
ANSWER: C
A. alert
B. backslash
C. tab
D. form feed
ANSWER: B
A. integer
B. boolean
C. character
ANSWER: B
A. enumeration
B. classes
C. both a and b
D. int
ANSWER: C
A. f is a function taking an argument of type int and retruning a floating point number
ANSWER: B
A. double
B. void
C. int
D. bool
ANSWER: A
9.When a language has the capability to produce new data type mean, it can be called as
A. overloaded
B. extensible
C. encapsulated
D. reprehensible
ANSWER: B
B. enumeration, classes
ANSWER: C
11.<< is called
A. Insertion operator
B. Extraction operator
C. Object
D. Function
ANSWER: A
12.>> is called
A. Insertion operator
B. Extraction operator
C. Object
D. Function
ANSWER: B
C. Iterative statement
D. Function
ANSWER: A
B. Test condition
ANSWER: A
ANSWER: A
ANSWER: B
A. cout
B. cin
C. header file
D. class
ANSWER: A
A. Function declaration
B. Function definition
C. Function call
D. Return type
ANSWER: A
C. Friend function
ANSWER: A
D. Anywhere
ANSWER: B
A. Actual parameter
B. Formal parameter
C. Global parameter
D. Auto parameter
ANSWER: A
A. Extern parameter
B. Formal parameter
C. Auto parameter
D. Register parameter
ANSWER: B
23.Which storage specifiers retains the value between the function call
A. Auto
B. Register
C. Extern
D. Static
ANSWER: D
24.If function does not return any value then its return type is
A. Int
B. Float
C. Void
D. Char
ANSWER: C
A. 1
B. 2
C. 0
D. 4
ANSWER: A
A. Function
B. File
C. Block
C. None
ANSWER: B
27.Which method of parameter passing does not change the original variable
A. Call by value
B. Call by reference
C. Call by pointers
D. Both b and c
ANSWER: A
B. Donald E. Knuth
D. Bjame Stroustrup
ANSWER: D
29.cfront
A. Pascal
B. Smalltalk
C. C
ANSWER: C
ANSWER: C
A. >>
B. ?:
C. .
ANSWER: D
A. class output
B. character output
C. common output
D. call output
ANSWER: C
A. start()
B. system()
C. main()
D. program()
ANSWER: C
36.What punctuation is used to signal the beginning and end of code blocks?
A. { }
D. ( and )
ANSWER: A
A. . (dot)
B. ; (semi-colon)
C. : (colon)
A. */ Comments */
B. ** Comment **
C. /* Comment */
D. { Comment }
ANSWER: C
A. float
B. real
C. int
D. double
ANSWER: B
A. :=
B. =
C. equal
D. ==
ANSWER: D
A. 1
B. 66
C. .1
A. &
B. &&
C. |
D. |&
ANSWER: B
43.The void specifier is used if a function does not have return type.
A. True
B. False
C. --
D. --
ANSWER: A
ANSWER: C
C. Both of these
D. None of these
ANSWER: A
46.There is a unique function in C++ program by where all C++ programs start their execution
A. Start()
B. Begin()
C. Main()
D. Output()
ANSWER: C
A. Parameters
B. Parenthesis
C. Curly braces
D. None of these
ANSWER: B
D. None of above
ANSWER: D
B. A Comma (,)
C. A Semicolon (;)
D. A colon (:)
ANSWER: C
ANSWER: D
ANSWER: B
ANSWER: B
53.What is encapsulation?
D. None of these
ANSWER: B
A. Letters
B. Digits
C. Underscores
D. Spaces
ANSWER: D
A. papername
B. writername
C. typename
D. printname
ANSWER: C
A. papername
B. writername
C. typename
D. printname
ANSWER: A
58.To increase the value of c by one which of the following statement is wrong?
A. c++;
B. c = c + 1;
C. c + 1 => c;
D. c += 1
ANSWER: C
D. All of these
ANSWER: A
60.What is the final value of x when the code int x; for(x=0; x<10; x++) {} is run?
A. 10
B. 9
C. 0
D. 1
ANSWER: A
Answer:d
Q2.which datatype is used to represent the absence of paramaters?
a) int
b) short
c) void
d) float
Answer:c
Answer:a
Q4.When a language has the capability to produce new data type mean, it can be called as
a) overloaded
b) extensible
c) encapsulated
d) reprehensible
Answer:b
Q5.In which type does the enumerators are stored by the compiler?
a) string
b) integer
c) float
d) none of the mentioned
Answer:b
Answer:d
Answer:a
Answer:a
Q9.Which allows you to create a derived class that inherits properties from more than one base class?
a. Multilevel inheritance
b. Multiple inheritance
c. Hybrid Inheritance
d. Hierarchical Inheritance
Answer:b
Answer:b
Q11. A function that changes the state of the cout object is called a(n) _____
a. member
b. adjuster
c. manipulator
d. operator
Answer:c
Q12. What does C++ append to the end of a string literal constant?
a. a space
b. a number sign (#)
c. an asterisk (*)
d. a null character
Answer:d
Answer:d
Q14. To hide a data member from the program, you must declare the data member in the _____ section of the class
a. concealed
b. confidential
c. restricted
d. private
Answer:d
Q15.The arguments that determine the state of the cout object are called
a. classes
b. manipulators
c. format flags or state flags
d. state controllers
Answer:c
Q16.Which of the following statements declares a variable that can contain a decimal number?
a. dec payRate;
b. dec hourlyPay
c. float payRate
d. float hourlyPay;
Answer:d
Answer:c
Answer:a
Answer:c
Answer:b
Answer:c
Q22. Which of the following type casts will convert an Integer variable named amount to a Double type?
a. (double) amount
b. (int to double) amount
c. int to double(amount)
d. int (amount) to double
Answer:a
Answer:d
Q24. You have assigned the address of Value to the pointer P, Which statement will display the value stored in
Value?
a. cout<<P;
b. cout<<*Value;
c. cout<<&P;
d. cout<<*<P;
Answer:d
Answer:b
Answer:a
Q27. Does this mentioning array name gives the base address in all the contexts?
a. Yes
b. No
Answer:b
Answer:b
Q29. Are the expressions arr and &arr same for an array of 10 integers?
a. Yes
b. No
Answer:b
Q30.The correct statement for a function that takes pointer to a float, a pointer to a pointer to a char and returns a
pointer to a pointer to a integer is
a) int **fun(float**, char**)
b) int *fun(float*, char*)
c) int ***fun(float*, char**)
d) int ***fun(*float, **char)
Answer:c
Answer:c
Answer:c
Answer:b
Q34. Which other keywords are also used to declare the class other than class?
a) struct
b) union
c) object
d) both a & b
Answer:d
Answer:a
Answer:b
Answer:a
Q38. When struct is used instead of the keyword class means, what will happen in the program?
a) access is public by default
b) access is private by default
c) access is protected by default
d) none of the mentioned
Answer:a
Answer:a
Answer:c
Q41. Which of these following members are not accessed by using direct member access operator?
a) public
b) private
c) protected
d) Both a & b
Answer:d
Answer:d
Answer:d
Q44. Which special character is used to mark the end of class?
a) ;
b) :
c) #
d) $
Answer: a
Answer: D
Answer: C
Answer:a
Answer:b
Answer:a
Answer:c
Answer:a
Answer:a
Answer:b
Answer:b
Answer:c
Answer:b
Answer:d
Answer: d
Answer: e
Answer: b
Answer: c
Answer: a
Answer: b
Answer:a
Answer: b
Answer:a
Answer: b
Answer:a
Answer:a
Q70. The entire set of data & code of an object can be made which data type using the concept of class
a. User-defined
b. static
c. global
d. derived
Answer:a
Answer:c
Q72. What provide the interface between the object’s data & the program
a. Data
b. class
c. methods
d.Encapsulation
Answer:c
Q73. The insulation of data from direct access by the program is called as
a. Encapsulation
b. Data hiding
c. Private
d. Data Abstraction
Answer:b
Q74. What is the process by which object of one class acquires the properties of object of another class.
a. Encapsulation
b. Data hiding
c. Inheritance
d.Polymorphism
Answer:c
Answer:b
Answer:b
Q77. The class from which the subclass derives the properties is called as
a. mainclass
b. subclass
c. baseclass
d. Superclass
Answer:d
Q78. The property or the ability to take more than one form is called as
a. Encapsulation
b. Polymorphism
c. Inheritance
d. Manyforms
Answer:b
Answer:c
Q80. The process of linking of a procedure call with the code to be executed is called as
a. Binding
b. Loading
c. Assembling
d. Debuging
Answer:a
Q81. What is the process in which the code to be linked with the procedure call is not know till execution time
?
a. Binding
b. early binding
c. static binding
d. dynamic binding
Answer:d
Q82. When the code to be linked with the call is known at compile time that situation is called as
a. Binding
b. late binding
c. static binding
d. dynamic binding
Answer:c
Answer: a
Answer: b
Q85. The binding of a function call at runtime is
a) Static binding
b) Early binding
c) Late binding
d) Runtime binding
Answer: c
Answer: d
Answer: b
Q88. Which constructor will initialize the base class data member?
a) derived class
b) base class
c) class
d) None of the mentioned
Answer:b
Q89. A remote control that is used to turn on or off some machine is also called a(n) _____.
a) class
b) interface
c) message
d) instance
Answer:b
Q90. In a student grading system, Student Last Name, Student Address, and Final Course Grade would all be
classified as what?
a)Inheritance
b)Information
c)Encapsulation
d)Polymorphism
Answer:b
Q91. What part of object-oriented technology defines superclass and subclass relationships?
a) Inheritance
b) Scalability
c) Encapsulation
d) Polymorphism
Answer:a
Q92. In a student grading system, objects from different classes communicate with each other. These
communications are known as _____.
a) inheritance
b) polymorphism
c) messages
d) concealment
Answer:c
Answer:d
Q94. What term is used to describe the internal representation of an object that is hidden from view outside the
object's definition?
a) Encapsulation
b) Expandable
c) Polymorphism
d) Inheritance
Answer:a
Q95. What programming language model is organized around "objects" rather than "actions"?
a) Java
b) OOB
c) Perl
d) C+
Answer:b
Q96. What are the instructions called that tell a system what, how, and when to do something?
a) Object-oriented technology approach
b) Object-oriented database
c) Program
d) Database management
Answer:c
Q97. What common technique attempts to save time and energy by reducing redundant work in object-oriented
programming?
a) Reduce lines of programming
b) Reuse of code
c) Reduce size of systems being developed
d) Merging different systems together
Answer:b
Answer:a
Answer:b
Answer: D
Answer:a
Answer:b
Answer:a
Answer:c
Q106. If a class C is derived from class B, which is derived from class A, all through public
inheritance, then a class C member function can access
a) protected and public data only in C and B.
b) protected and public data only in C.
c) private data in A and B.
d) protected data in A and B.
Answer:d
Answer:d
Answer:b
Q109. In C++, dynamic memory allocation is accomplished with the operator ____
a) new
b) this
c) malloc( )
d) delete
Answer:a
Answer: c
Answer:c
Answer:a
Answer:d
Answer:c
Answer:d
Answer:c
Answer:d
Answer:c
Q119.Given a class named Book, which of the following is not a valid constructor?
a) Book ( ) { }
b) Book ( Book b) { }
c) Book ( Book &b) { }
d) Book (char* author, char* title) { }
Answer:b
Q120.Which of the statements is true in a protected derivation of a derived class from a base class?
a) Private members of the base class become protected members of the derived class
b) Protected members of the base class become public members of the derived class
c) Public members of the base class become protected members of the derived class
d) Protected derivation does not affect private and protected members of the derived
class.
Answer:c
Answer:d
Answer:c
Answer:b
Q124.If there is a pointer p to object of a base class and it contains the address of an object of a
derived class and both classes contain a virtual member function abc(), then the statement
p->abc(); will cause the version of abc() in the __________class to be executed.
a) Base Class
b) Derived class
c) Produces compile time error
d) produces runtime error
Answer:b
Q125.We can output text to an object of class ostream using the insertion operator<< because
a) the ostream class is a stream
b) the insertion operator works with all classes.
c) we are actually outputting to cout.
d) the insertion operator is overloaded in ostream.
Answer:d
Answer:d
Q127.Name the header file to be included for the use of built in function isalnum()
a) string.h
b) process.h
c) ctype.h
d) dos.h
Answer:c
Answer:a
Answer:c
Answer:b
Answer:b
Answer:a
Q133.Which of the following ways are legal to access a class data member using this pointer?
a) this.x
b) *this.x
c) *(this.x)
d) (*this).x
Answer:d
Answer:c
Answer:d
Answer:d
Answer:d
Answer:a
Answer:c
Q140.Data members which are static
a) cannot be assigned a value
b) can only be used in static functions
c) cannot be defined in a Union
d) can be accessed outside the class
Answer:b
Q141.this pointer
a) implicitly points to an object.
b) can be explicitly used in a class.
c) can be used to return an object.
d) All of the above.
Answer:d
Answer:b
Answer:c
Answer: a
Answer: a
Answer: B
Q.146. Which of the following term is used for a function defined inside a class?
A. Member Variable
B. Member function
C. Class function
D. Classic function
Answer: B
Answer: D
Answer: C
Answer: B
Q.150 Which header file must be included for cin and cout?
(A) stdio.h
(B) conio.h
(C) iostream.h
(D) Both iostream.h and conio.h
Answer: C
Q.151 Which one of the following is correct about the statements given below?
A. Only II is correct.
B. Both I and II are correct.
C. Only I is correct.
D. Both I and II are incorrect.
Answer: C
Answer: B
A. none of these
B. their own header files
C. Auxiliary .cpp file
D. main .cpp files, along with function definitions
Answer: B
Answer: B
Answer: C
Answer: C
Answer: C
Answer:b
Answer:b
Answer: C
Q161.“H” is an example of
a) character literal
b) string literal
c) variable
d) None of the above
Answer: B
Answer: C
Answer: C
Answer: C
a) inside loop
b) outside loop
c) both (a) & (b)
d) none of the above
Answer: B
Answer: A
Answer: C
Answer: D
Answer: B
Answer: D
Answer:b
Answer:c
Answer:b
Answer:c
Q.176. When a language has the capability to produce new data type mean, it can be called as
a) overloaded
b) extensible
c) encapsulated
d) reprehensible
Answer:b
Answer:d
Answer:c
Answer:b
Q.182 For what values of the expression is an if-statement block not executed?
a) 0 and all negative values
b) 0 and -1
c) 0
d) 0, all negative values, all positive values except 1
Answer:c
Q.183 Which of the two operators ++ and — work for the bool datatype in C++?
a) None
b) ++
c) –
d) Both
Answer:b
#include <iostream>
using namespace std;
int f(int p, int q)
{
if (p > q)
return p;
else
return q;
}
main()
{
int a = 5, b = 10;
int k;
bool x = true;
bool y = f(a, b);
k =((a * b) + (x + y));
cout << k;
}
a) 55
b) 62
c) 52
d) none of the mentioned
Answer:c
#include <iostream>
using namespace std;
int main()
{
int p;
bool a = true;
bool b = false;
int x = 10;
int y = 5;
p = ((x + y) + (a + b));
cout << p;
return 0;
}
a) 0
b) 16
c) 12
d) 2
Answer:b
Answer:b
Answer:c
Answer:a
#include <stdio.h>
int main()
{
char a = '\012';
printf("%d", a);
return 0;
}
a) Compiler error
b) 12
c) 10
d) Empty
Answer:c
Q.191 In C++, what is the sign of character data type by default?
a) Signed
b) Unsigned
c) Implementation dependent
d) None of these
Answer:c
Answer:c
Answer:c
#include <iostream>
using namespace std;
int main()
{
int x = -1;
unsigned int y = 2;
if(x > y) {
cout << "x is greater";
} else {
cout << "y is greater";
}
}
a) x is greater
b) y is greater
c) Implementation defined
d) Arbitrary
Answer:a
Q.195 Which of these expressions will return true if the input integer v is a power of two?
a) (v | (v + 1)) == 0;
b) (v & (v – 1)) == 0;
c) (v | (v + 1)) == 0;
d) (v & (v – 1)) == 0;
Answer:d
Q.196 What is the value of the following 8-bit integer after all statements are executed?
int x = 1; 2 Marks
x = x << 7;
x = x >> 7;
a) 1
b) -1
c) 127
d) Implementation defined
View Answer
Answer:d
Q.197 What is the value of the following 8-bit integer after all statements are executed?
int x = 1;
x = x << 7; 2 Marks
x = x >> 7;
a) 1
b) -1
c) 127
d) Implementation defined
Answer:d
Q.198 Which of these expressions will make the rightmost set bit zero in an input integer x?
a) x = x | (x-1)
b) x = x & (x-1)
c) x = x | (x+1)
d) x = x & (x+1)
Answer:b
Q.199 Which of these expressions will isolate the rightmost set bit?
a) x = x & (~x)
b) x = x ^ (~x)
c) x = x & (-x)
d) x = x ^ (-x)
Answer:c
Q.200 Which of these expressions will isolate the rightmost set bit?
a) x = x & (~x)
b) x = x ^ (~x)
c) x = x & (-x)
d) x = x ^ (-x)
Answer:c
#include <iostream>
using namespace std;
int main()
{
int a = 8;
cout << "ANDing integer 'a' with 'true' :" << a && true;
return 0;
}
a) ANDing integer ‘a’ with ‘true’ :8
b) ANDing integer ‘a’ with ‘true’ :0
c) ANDing integer ‘a’ with ‘true’ :1
d) None of the mentioned
Answer:a
#include <iostream>
using namespace std;
int main()
{
int i = 3;
int l = i / -2;
int k = i % -2;
cout << l << k;
return 0;
}
a) compile time error
b) -1 1
c) 1 -1
d) implementation defined
Answer:b
int main()
{
register int i = 1;
int *ptr = &i;
cout << *ptr;
return 0;
}
a) 0
b) 1
c) Compiler error may be possible
d) Runtime error may be possible
Answer:c
Answer:b
Q.205 In which type does the enumerators are stored by the compiler?
a) string
b) integer
c) float
d) none of the mentioned
Answer:b
Answer:d
Answer:a
Answer:a
#include <iostream>
using namespace std;
enum cat {
temp = 7
};
int main()
{
int age = 14;
age /= temp;
cout << "If you were cat, you would be " << age << endl;
return 0;
}
a) If you were cat, you would be 5
b) If you were cat, you would be 2
c) If you were cat, you would be 7
d) none of the mentioned
Answer:b
Answer:a
#include <iostream>
using namespace std;
enum colour {
green, red, blue, white, yellow, pink
};
int main()
{
cout << green<< red<< blue<< white<< yellow<< pink;
return 0;
}
a) 0123456
b) 1111111
c) compile time error
d) runtime error
Answer:a
#include <iostream>
using namespace std;
int main()
{
enum channel {star, sony, zee};
enum symbol {hash, star};
int i = 0;
for (i = star; i <= zee; i++) {
printf("%d ", i);
}
return 0;
}
a) 012
b) 123
c) compile time error
d) runtime error
Answer:c
#include <iostream>
using namespace std;
int main()
{
int i;
enum month {
JAN = 1, FEB, MAR, APR, MAY, JUN, JUL, AUG, SEP, OCT, NOV, DEC
};
for (i = MAR; i <= NOV; i++)
cout << i;
return 0;
}
a) 01234567891011
b) 123456789101112
c) 34567891011
d) 123456789
Answer:c
Answer:C
Answer:c
Answer:b
Q.217 Which other keywords are also used to declare the class other than class?
a) struct
b) union
c) object
d) both a & b
Answer:d
#include <iostream>
using namespace std;
class rect
{
int x, y;
public:
void val (int, int);
int area ()
{
return (x * y);
}
};
void rect::val (int a, int b)
{
x = a;
y = b;
}
int main ()
{
rect rect;
rect.val (3, 4);
cout << "rect area: " << rect.area();
return 0;
}
a) rect area:12
b) rect area: 12
c) rect area:24
d) none of the mentioned
Answer:b
#include <iostream>
using namespace std;
class CDummy
{
public:
int isitme (CDummy& param);
};
int CDummy::isitme (CDummy& param)
{
if (¶m == this)
return true;
else
return false;
}
int main ()
{
CDummy a;
CDummy *b = &a;
if (b->isitme(a)) {
cout << "execute";
}
else
{
cout<<"not execute";
}
return 0;
}
a) execute
b) not execute
c) none of the mentioned
d) both a & b
Answer:a
Answer:a
Answer:b
Answer:a
Q.223 When struct is used instead of the keyword class means, what will happen in the program?
a) access is public by default
b) access is private by default
c) access is protected by default
d) none of the mentioned
Answer:a
Answer:a
Answer:c
Q.226 Which of these following members are not accessed by using direct member access operator?
a) public
b) private
c) protected
d) Both a & b
Answer:d
#include <iostream>
using namespace std;
class Box
{
public :
double length;
double breadth;
double height;
};
int main( )
{
Box Box1;
double volume;
Box1.height = 5;
Box1.length = 6;
Box1.breadth = 7.1;
volume = Box1.height * Box1.length * Box1.breadth;
cout << "Volume of Box1 : " << volume <<endl;
return 0;
}
a) 210
b) 213
c) 215
d) 217
Answer:b
Answer:a
Answer:d
Answer:d
#include <iostream>
using namespace std;
class sample
{
private:
int var;
public:
void input()
{
cout << var;
}
void output()
{
cout << "Variable entered is ";
cout << var << "\n";
}
};
int main()
{
sample object;
object.input();
object.output();
object.var();
return 0;
}
a) Enter an integer 5
Variable entered is 5
b) runtime error
c) error
d) none of the mentioned
Answer:c
Answer:a
Answer: a
#include <iostream>
using namespace std;
class number
{
int i;
public:
int geti();
void puti(int j);
};
int number::geti()
{
return i;
}
void number::puti(int j)
{
i = j;
}
int main()
{
number s;
s.puti(10);
cout << s.geti( );
return 0;
}
a) 10
b) 11
c) 20
d) 22
Answer:a
Answer:a
Answer:b
Answer:b
Q.238 What is the output of this program? 2 Marks
#include <iostream>
using namespace std;
class p
{
protected:
int width, height;
public:
void set_values (int a, int b)
{
width = a; height = b;
}
virtual int area (void) = 0;wa
};
class r: public p
{
public:
int area (void)
{
return (width * height);
}
};
class t: public p
{
public:
int area (void)
{
return (width * height / 2);
}
};
int main ()
{
r rect;
t trgl;
p * ppoly1 = ▭
p * ppoly2 = &trgl;
ppoly1->set_values (4, 5);
ppoly2->set_values (4, 5);
cout << ppoly1 -> area() ;
cout << ppoly2 -> area();
return 0;
}
a) 1020
b) 20
c) 10
d) 2010
Answer:d
#include <iostream>
using namespace std;
class MyInterface
{
public:
virtual void Display() = 0;
};
class Class1 : public MyInterface
{
public:
void Display()
{
int a = 5;
cout << a;
}
};
class Class2 : public MyInterface
{
public:
void Display()
{
cout <<" 5" << endl;
}
};
int main()
{
Class1 obj1;
obj1.Display();
Class2 obj2;
obj2.Display();
return 0;
}
a) 5
b) 10
c) 5 5
d) None of the mentioned
Answer:c
#include <iostream>
using namespace std;
class sample
{
public:
virtual void example() = 0;
};
class Ex1:public sample
{
public:
void example()
{
cout << "ubuntu";
}
};
class Ex2:public sample
{
public:
void example()
{
cout << " is awesome";
}
};
int main()
{
sample* arra[2];
Ex1 e1;
Ex2 e2;
arra[0]=&e1;
arra[1]=&e2;
arra[0]->example();
arra[1]->example();
}
a) ubuntu
b) is awesome
c) ubuntu is awesome
d) None of the mentioned
Answer:c
#include <iostream>
using namespace std;
class Base
{
public:
virtual void print() const = 0;
};
class DerivedOne : virtual public Base
{
public:
void print() const
{
cout << "1";
}
};
class DerivedTwo : virtual public Base
{
public:
void print() const
{
cout << "2";
}
};
class Multiple : public DerivedOne, DerivedTwo
{
public:
void print() const
{
DerivedTwo::print();
}
};
int main()
{
Multiple both;
DerivedOne one;
DerivedTwo two;
Base *array[ 3 ];
array[ 0 ] = &both;
array[ 1 ] = &one;
array[ 2 ] = &two;
for ( int i = 0; i < 3; i++ )
array[ i ] -> print();
return 0;
}
a) 121
b) 212
c) 12
d) None of the mentioned
Answer:b
Answer:a
Answer:a
Answer:d
Q.245 In which direction does the assignment operation will take place?
a) left to right
b) right to left
c) top to bottom
d) None of the mentioned
Answer:b
Answer:c
#include <iostream>
using namespace std;
int main ()
{
int a, b;
a = 10;
b = 4;
a = b;
b = 7;
cout << "a:";
cout << a;
cout << " b:";
cout << b;
return 0;
}
a) a:4 b:7
b) a:10 b:4
c) a:4 b:10
d) None of the mentioned
Answer:a
#include <iostream>
using namespace std;
int main ()
{
int a, b, c;
a = 2;
b = 7;
c = (a > b) ? a : b;
cout << c;
return 0;
}
a) 2
b) 7
c) 9
d) 14
Answer:b
Q.249 What is the output of this program? 2 Marks
#include <iostream>
using namespace std;
int main()
{
int a = 0;
int b = 10;
if ( a && b )
{
cout << "true"<< endl ;
}
else
{
cout << "false"<< endl ;
}
return 0;
}
a) true
b) false
c) error
d) None of the mentioned
Answer:b
Q.250 Where does the default parameter can be placed by the user?
a) leftmost
b) rightmost
c) both a & b
d) none of the mentioned
Answer:b
Unit 2 : Classes & Objects
Question Bank
A. Class
B. Constructor
C. Destructors
D. Attributes
Ans : A
Explanation: In class, only all the listed items except class will be declared.
2)Constructor is executed when __ _.
A. Class A { int x; };
B. Class B { }
C. Public class A { }
D. Object A { int x; };
Ans : A
A. Default
B. Break
C. Protected
D. Asm
Ans : C
A. +
B. ::
C. -
D. *
Ans : B
A. 0
B. 2
C. 4
D. 1
Ans : D
Explanation: When we create object of empty class at that time State of that object is nothing.
Behaviour of that object is also nothing, but compiler assigns a unique address to that object.
Memory in Computer is always organized in the form of bytes and minimum memory available at
object address location is 1 byte. That's why size of object of empty class is 1 byte.
8) How to access the object in the class?
A. Ternary operator
B. Scope resolution operator
C. Direct member access operator
D. None of the above
Ans : C
Explanation: Objects in the method can be accessed using direct member access operator which is
(.).
9) When struct is used instead of the keyword class means, what will happen in the program?
Explanation: Access is public by default will happen Whenstruct is used instead of the keyword
class.
10) Which of the following is not a member of class?
A. Static Function.
B. Friend Function
C. Const Function
D. Virtual Function
Ans : B
Answer: (D)
Explanation: Header file can not be passed to a function in C++. While array, constant and
structure can be passed into a function.
So, option (D) is correct.
12) Which of the following is not a correct statement?
(A) Every class containing abstract method must be declared abstract.
(B) Abstract class can directly be initiated with ‘new’ operator.
(C) Abstract class can be initiated.
(D) Abstract class does not contain any definition of implementation.
Answer: (B)
Explanation:
• Every class containing abstract method must be declared abstract. Correct Declaration is
required.
• Abstract class can directly be initiated with ‘new’ operator. No it can’t be initiated directed by
only ‘new’ operator. So, it is Inorrect
• Abstract class can be initiated.Correct
• Abstract class does not contain any definition of implementation.Correct
So, option (B) is correct.
Answer: (B)
Explanation: Every object maintains a copy of non-static data members. For example, let
Student be a class with data members as name, year, batch. Every object of student will have its
own name, year and batch. On a side note, static data members are shared among objects.
All objects share codes of all methods. For example, every student object uses same logic to find
out grades or any other method.
14) A member function can always access the data in _______ _ , (in C++).
(A) the class of which it is member
(B) the object of which it is a member
(C) the public part of its class
(D) the private part of its class
Answer: (A)
Explanation: A member function can access it’s class member variables, irrespective of the
access specifier in which the member variable is declared.So, a member function can always
access the data in the class of which it is a member.
So, option (A) is correct.
15) Data members and member functions of a class in C++ program are by default
A. protected
B. public
C. private
D. None
View Answer
Answer: C
16) Which operator is used to allocate an object dynamically of a class in C++?
A. :
A. Constructor
B. Destructor
C. Copy constructor
D. Assignment operator
E. All
Answer: E
19) When you create an object of a class A like A obj ; then which one will be called
automatically
A. Constructor
B. Destructor
C. Copy constructor
D. Assignment operator
Answer: A
20) The class in C++ which act only as a base class and object of it cannot be created is
A. parent class
B. super class
C. abstract class
D. none of the above
Answer: C
Q.004 If class A has add() function with protected access, and few other members in public.
Then class B inherits class A privately. Will the user will not be able to call __
from the object of class B.
A Any function of class A
B The add() function of class A
C Any member of class A
D Private, protected and public members of class A
Correct D
Q.005 If an abstract class has all the private members, then _
A No class will be able to implement members of abstract class
B Only single inheritance class can implement its members
C Only other enclosing classes will be able to implement those members
D No class will be able to access those members but can implement.
Correct A
Q.006 If the protected members are to be made accessible only to the nearest subclass and no
further subclasses, which access specifier should be used in inheritance?
A The sub class should inherit the parent class privately
B The sub class should inherit the parent class as protected
C The sub class should inherit the parent class as public
D The sub class can use any access modifier
Correct A
Q.007 Except constructors, if all the members are defined in protected specifier then ___
A Instance of class can’t be created
B Instance of class can be created anywhere
C Instance of class can be created only in subclasses
D Instance of class can be created only in main() function
Correct B
Q.008 If protected inheritance is used then _
A Public members become public in subclass
B Protected members become public in subclass
C Protected members become protected in subclass
D Protected and Public members become protected in subclass
Correct D
Correct C
Q.031 What is the role of a constructor in classes?
A To modify the data whenever required
B To destroy an object
C To initialize the data members of an object when it is created
D To call private functions from the outer world
Correct C
Q.032 What will be the output of the following C++ code?
A Error
UNIT II MCQ
B. Friend constructor
C. Default constructor
D. Parameterized constructor
Answer: Option B
C. Const function
D. Virtual function
Answer: Option B
5. Which of the following concepts means determining at runtime what method to invoke?
A. Data hiding
B. Dynamic Typing
C. Dynamic binding
D. Dynamic loading
Answer: Option C
6. Which of the following term is used for a function defined inside a class?
A. Member Variable
B. Member function
C. Class function
D. Classic function
Answer: Option B
7. Which of the following concept of oops allows compiler to insert arguments in a function
call if it is not specified?
A. Call by value
B. Call by reference
C. Default arguments
D. Call by pointer
Answer: Option C
B.5
C. 13
D. 0
B. Class
C. Object
D. Operator function
Answer: Option C
Answer: Option a
13. True/False: A class can serve as base class for many derived classes.
Answer: True
14. When a class serves as base class for many derived classes, the situation is called:
a. polymorphism
b. hierarchical inheritance
c. hybrid inheritance
d. multipath inheritance
e. none of these
Answer: (b)
15. When two or more classes serve as base class for a derived class, the situation is known as
_ .
a) multiple inheritance
b) polymorphism
d) hierarchical inheritance
e) none of these
Answer: (a)
16. Which of the following statement is correct?
A. A constructor is called at the time of declaration of an object.
Answer: Option A
D. Initialize objects
Answer: Option D
21. Which of the following is correct about the statements given below?
All operators can be overloaded in C++.
We can change the basic meaning of an operator in C++.
A. Only I is true.
C. Only II is true.
D. Both I and II are true.
Answer: Option B
22. What happens if the base and derived class contains definition of a function with same
prototype?
A. Compiler reports an error on compilation.
B. Multilevel
C. Distributive
D. Hierarchical
Answer: Option C
D. Both A and C.
Answer: Option D
B. ->
C. ?:
D. *
Answer: Option C
B. operator
C. friend
C. Hybrid inheritance
D. Hierarchical Inheritance
Answer: Option B
32. Which of the following is an invalid visibility label while inheriting a class?
A. public
B. private
C. protected
D. friend
Answer: Option D
C. Dynamic binding
D. Encapsulation
Answer: Option B
35. When a function is defined inside a class, this function is called ………….
A) Inside function
B) Class function
C) Inline function
D) Interior function
Answer B) +
39. Which of the following is true about the static member variable in C++.
i) It is initialized to zero when the first object of its class is created. Other initialization is also
permitted.
ii) It is visible only within the class, but its lifetime is the entire program.
A) i-True, ii-True
B) ii-False, ii-True
C) i-True, ii-False
D) i-False, iii-False
40. Which of the following keywords are used to control access to a class member?
A) default
B) break
C) protected
D) goto
Answer C) protected
41. What will be the values of x, m and n after execution of the following statements?
Int x, m, n;
m=10;
n=15;
x= ++m + n++;
43. A variable is defined within a block in a body of a function. Which of the following are true?
A) It is visible throughout the function.
B) It is visible from the point of definition to the end of the program.
C) It is visible from the point of definition to the end of the block.
D) It is visible throughout the block.
48. Constructor is
A. A class automatically called whenever a new object of this class is created
B. A class automatically called whenever a new object of this class is destroyed
C. A function automatically called whenever a new object of this class is created
D. A function automatically called whenever a new object of this class is destroyed
Answer: Option C
51. What happens when we try to compile the class definition in following code snippet?
C. It will not compile because a class cannot be protectedly inherited from other class.
Answer: Option D
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.
Answer: Option D
Answer: Option D
Answer: Option B
57. 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
58. Which of the following statements is correct about the constructors and destructors?
Answer: Option B
59. 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
60. 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.
Answer: Option B
61. Which of the following keywords is used to control access to a class member?
B. Break
C. Protected
D. Asm
Answer: Option C
73.. What is required in inheritance to initialize the data members of the base class through derived
class?
A) Object declaration
B) Destructor
C) Constructor
D) Inheritance
Answer:C) Constructor
75. Which of the statements is true in a protected derivation of a derived class from a base class?
A) Private members of the base class become protected members of the derived class
B) Protected members of the base class become public members of the derived class
C) Public members of the base class become protected members of the derived class
D) Protected derivation does not affect private and protected members of the derived class
76. When the access specifier of the base class in the derived class definition is public, the base
class is ..
A) Publicly inherited
B) Protectedly inherited
C) Privately inherited
79. The constructor and the destructor of a class are automatically invoked when memory is
allocated and deallocated to an ....
A) Data type
B) Copy constructor
C) Object
Answer:C) Object
A) has no body
B) returns nothing
A) Nested Class
B) Inheritance
C) Containership
D) Encapsulation
Answer:A) Nested Class
A) Reference
B) Pointer
C) Array
Answer:B) Pointer
Answer:a
Explanation:Because array variable and values need to be declared after the datatype only.
84. What is the index number of the last element of an array with 9 elements?
a) 9
b) 8
c) 0
d) Programmer-defined
Answer:b
Explanation:Because the first element always starts at 0. So it is on 8 position.
Answer:a
Explanation:None.
86. Which of the following accesses the seventh element stored in array?
a) array[6];
b) array[7];
c) array(7);
d) array;
Answer:a
Explanation:The array location starts from zero, So it can accessed by array[6].
87. Which of the following gives the memory address of the first element in array?
a) array[0];
b) array[1];
c) array(2);
d) array;
Answer:d
#include <stdio.h>
using namespace std;
int array1[] = {1200, 200, 2300, 1230, 1543};
int array2[] = {12, 14, 16, 18, 20};
int temp, result = 0;
int main()
{
for (temp = 0; temp < 5; temp++) {
result += array1[temp];
}
for (temp = 0; temp < 4; temp++) {
result += array2[temp];
}
cout << result;
return 0;
}
Answer:b
Explanation:In this program we are adding the every element of two arrays. Finally we got output
as 6533.
Output:
$ g++ array.cpp
$ a.out
6533
#include <stdio.h>
using namespace std;
int main ()
{
int array[] = {0, 2, 4, 6, 7, 5, 3};
int n, result = 0;
for (n = 0; n < 8; n++) {
result += array[n];
}
cout << result;
return 0;
}
a) 25
b) 26
c) 27
d) None of the mentioned
Answer:d
Explanation:We are adding all the elements in the array and printing it. Total elements in the
array is 7, but our for loop will go beyond 7 and add a garbage value.
#include <stdio.h>
using namespace std;
int main()
{
a) ABC
b) ABCD
c) AB
d) None of the mentioned
Answer:a
Explanation:We are just printing the values of first 3 values.
$ g++ array.cpp
$ a.out
ABC
A. Classname Objectname;
B. Class Classname Objectname;
C. Class Classname Object Objectname;
D. Classname Object Objectname;
Answer: Option A
A. May be declared
B. Can be initialized
C. Cannot be intialized
D. Cannot be declared
Answer: Option D
1 Which of the following term is used for a Member Variable Member function Class function Classic function
function defined inside a class?
2 Classes are useful because they are removed from permit data to be hidden bring together all aspects can closely model
memory when not in use from other classes of an entity in one place objects in the real
world
3 Which member function of class cannot friend functions Private member functions Constant member Static member
modify its objects attributes ? functions functions
4 Which of the following is an abstract data int double string Class
type?
5 Which of the following statement is correct? Object is an instance of a Class is an instance of data Object is an instance of Class is an instance
class. type. data type. of object
6 Which of the following is correct about class class can have member class data members are Pointer to structure or class data members
and structure? functions while structure public by default while classes cannot be are private by
cannot. that of structure are private declared. default while that of
structure are public
by default.
7 What does your class can hold? Data Functions Both A & B None of the above
8 What is object in C++ ? Object is function of a Object is an instance of a Object is datatype of a Object is part of
class. class. class. syntax of a class
9 How many specifier are present as access 1 2 3 4
specifier in a class in C++?
10 Which operator is used to define the member : :: # None Of The
of a class externally? Mentioned
11 Which of the following is a valid class class A { int x; }; class B { } public class A { } object A { int x; };
declaration?
12 The fields in the class in c++ program are by protected private public none of the
default mentioned
13 What is class in c++ ? When you define a class, When you define a class, A. When you define a When you define a
you define a blueprint for you add more class, you define class, you make
a data type functionality. the logic. debugging.
20 The new operator returns a pointer to the creates a variable called obtains memory for a tells how much
variable new new variable memory is
available
24 ::count means ----- Local version of the Global version of the Both local and global All of these
variable count variable count version of count
25 The scope resolution operator is a semicolon(;) a colon(:) two colons(::) a comma(,)
37 Instead of the class if use struct then _ _. access in the public by access is private by default access is protected by none of these
default default
38 choose the correct statement. only data members are only member functions both data and member . the member
private are public functions can be public functions are private
39 Which of the following is not validity access public private protected extern
specifier in the class ?
40 A class cannot be _ _. virtual friend generic inline
41 What is the purpose of keyword inline? it allows one line function . it causes the replacement it indicates the function it tells compiler to
declaration of function calls by the declaration use that function in
code from the function the same source
code file
42 Which of the following is a valid inline public private protected extern
function 'myfun'?
43 inline void myfun() void myfun() inline inline:: void none of these
{//functon code} {//function code} myfun{//function code}
44 Following is a main benefit of the inline it decrease the size of the it simplifies the source it increases the speed of it removes
function/ program code the resulting program unnecessary
function
45 Following is a limit on inline function. inline function can not inline function has to inline function must have the compiler can
return a values return a value less than 10 lines of code choose to ignore an
inline directive.
46 When will you make a function inline? if that function is small . if the function is small if the function is not if the function is not
and not called frequently but called frequently small but called small and not called
frequently frequently
47 The fields in class of C++ program are _ _. . public private protected none of these
48 Which of the following keyword is used to const switch private for
control the access of data members of a class
?
49 What arrays in the C++? . A series of elements of A series of elements of A series of elements of A series of elements
same type placed in different type placed in same type placed in non- of different type
continuous block of continuous block of continuous block of placed in non-
memory memory memory continuous block of
memory
50 The memory address for array can be obtained a[0] address_of(a) a[1] a
using .
51 What is the output of the following code? 42 30 garbage value syntax error
#include <iostream>
using namespace std;
class Test
{
private
int array[]={0,2,4,6,8,10,12};
public:
void computer();
};
void Test::compute()
{
int result=0;
for (int i=0;i<7;i++)
{
result+=array[i];
}
cout<<result;
}
int main()
{
test obj;
obj.compute();
return();
}
52 The size of heap memory is _ _. 100 MB 1024 MB 1024 GB determined by size
of RAM and swap
memory
53 How will you pass the large objects in C++? using call by value using call by reference either a or b none of these
method method
54 Objects of the same class shres the values of global variables and static non static and static static variables, non static local and static
_ and maintain separate values for _. variables variables
55 Which of the member functions of class private member functions constant member functions friend function static member
cannot modify its objects attributes ? function
56 How many types of classes are there? 1 2 3 4
57 How to access object in the class? using ternary operator using direct member scope resolution operator none of these
access operator
58 Constructors are used . to build a user interface deallocate memory initialize newly created to construct
objects functions
59 Which of the following member is not public private protected both B and C
accessible using the direct member access
operator?
60 If different objects are created the separate data members member functions both A ans B none of these
memory space is created for .
61 The memory required by any objects is size of non static data order of data members Byte padding all of these
dependent upon following factors members of the class
62 Which of the following is correct way of Class_name object_name; object_name class_name class class_name class class_name
declaring object of a class ? object_name object object_name
63 What is the output of the following code? 10 constructor invoked syntax error none of these
#include<iostream>
using namespace std;
class test
{
private:
int a;
public:
test(int x);
};
test::test(int x=10)
{
a=x;
cout<<"\n Constructor Invoked";
}
int main()
{
test obj1,*obj2;
return 0;
}
64 How many objects can be created by a single 1 2 3 as many as required
class?
65 The name of the constructor is . limited to 10 character same as the belonging main as per the
class name programmer's choice
66 What is the output of the following code? Constructor syntax error constructor copy constructor
#include <iostream> copy constructor copy constructor copy constructor
using namespace std; copy constructor constructor copy constructor
class test
{
private:
int a;
public:
test(int x);
test(test &);
};
test::test(int x=10)
{
a=x;
cout<<"\n CopyConstrustor";
}
int main()
{
test*obj1,*obj2;
obj1=new test (10);
obj2=new test(*obj1);
test *obj3;
obj3=new test(20);
return 0;
}
67 What is the output of the following code? 012 000 three garbage values syntax error
#include<iostream> .
using namespace std;
class test
{
private:
int a;
public:
test(int x)
void display();
};
test::test(int i)
{
a=i;
}
void test::display()
{
cout<<""<<a;
}
int main()
{
test obj[3];
obj[0].display();
obj[1].display();
obj[2].dispaly();
return 0;
}
68 What is the output of the following code? constructor constructor constructor destructor constructor constructor no output
#include<iostream> destructor destructor
using namespace std;
class test
{
private:
int a;
public:
test()
{
a=0;
cout<<"constructor";
}
~test()
{
cout<<"destructor";
}
};
int main()
{
test a[2];
return 0;
}
69 What is the output of the following code? 0 1 garbage value syntax error
#include<iostream>
using namespace std;
class test
{
private:
int a;
public:
test()
{
a=0;
count++;
}
void display()
{
cout<count;
}
};
int main()
{
test obj;
obj.display();
return 0;
}
70 What will be the output of the following syntax error nothing will be displayed Constructor destructor Constructor
code? constructor
class test
{
public:
test()
{cout< "constructor";}
~test()
{cout< "destructor";}
};
int main()
{
delete new test();
return 0;
}
71 The default constructor accepts _ one two three no
parameters.
72 If the default constructor is not defined then . it will cause syntax error it will cause runtime error the compiler will create none of these.
_ _ constructor for creating
an object
73 A class is not having default constructor but the desired object will get it will cause syntax error it will cause runtime error none of these
one parameterized constructor. created because compiler
We have created an object that needs zero will create an inplicit
argument constructor. What will happen in default constructor.
this case?.
74 The destructor is preceded by the symbol # ! ~ $
_
75 The constructors and destructors for an by making explicit call to when object enters and when inheritance occurs none of these
automatic object are invoked . constructor and destructor leaves its scope
functions
76 For copying the object of same class type default constructor dynamic constructor when inheritance occurs none of these
following type of constructor is defined
_
77 Which of the following is true about only I I,III and IV I and II I,II and III
constructor?
I. Constructor have same name as its class
name.
II. They constructors can be inherited
III. The constructor cannot be declared in
protected section.
IV. Constructor cannot return values.
78 Which of the following is not true about only I I and II I and III I,II and III
destructor?
I. It is preceded by dollar sign
II. It can be declared in private section
III. It can be parameterized
79 Object can be defined as _. attribute of class instance of a class member of a class none of these
80 The copy constructor _. creates an object from creates an object from an creates an object which is none of these
any object. object of same class pointer to copied object
81 For initializing the data members of class data members get creates an object from an creates an object which is none of these
_ _ is used. initialized automatically object of the same class. pointer to copied object
in C++
82 For initializing the data members of class _ data members get constructor destructor none of these
is used. initialized automatically
in C++
83 A class can have . all the constructors that only parameterized and only copy constructors only parameterized
are required copy constructors constructors
84 Which of the following statement is correct ?
A. constructors can have default parameters.
B. constructor cannot have default parameters.
C. constructor cannot have more than one
default parameters.
D. At the most 3 default parameters are
allowed for constructor.
ANSWER: A
85 Which constructor will execute in following constructor 1 constructor 2 constructor 3 syntax error
code?
class test{
public:
int a,b;
test(){a=b=1;}
test(int a){a=a;b=1;}
test(int a,int b){a=a;b=b;}
}
int main()
{
test obj(1,2);
return 0;
}
86 What value should destructor return ? status code that indicates pointer to class destructor does not return object of a class
that allocated memory for any value
object is freed.
87 Which of the following is nota type of default constructor parameterized constructor copy constructor public constructor
constructor?
88 Which of the following statement will invoke TEST T1(T2) T1=new Test(); T1=T2 none of these
copy constructor for class TEST?
89 Operator overloading is _. technique to work with technique which allows making new C++ giving new relevent
objects C++ to handle more than operators meaning to existing
one operators C++ operators
without changing
basis meaning
90 Operator function is created using _ allocator . constructor operator iterator
keyword.
91 How tp declare operator function ? operator function_name operator operator_sign() operator_sign none of these
92 Which of following operator cannot be + - :: []
overload?
93 Operator function must be _ . only 1 1 and 3 2 and 3 All 1,2 and 3
1. Non-static member function 2. Static
function 3. friend function
94 In C++ _ _ operator is used for dynamic Scope resolution operator conditional operator new arithmetic operator
memory allocation. +
95 While overloading binary operator using Zero argument one argument two arguments it depends upon the
member function it requires . operator to be
overloaded
96 What will be the output of the following 30 3 00 11 22 22 11
code?
99 Which of the following is a type of data members member function . both A and B none of these
inheritance?
100 Which of the following is a type of single inheritance and single and multiple Single ,multiple, single, multiple,
inheritance? multilevel inheritance inheritance multilevel inheritance multilevel
,hierarchical and
hybrid inheritance
]
101 In relationship an object of derived class encapsulation . polymorphism inheritance none of these
can also be treated as an object of its base
class.
102 For deriving the child class from the base :: : ; ->
class which symbol is used?
103 What will be output of following code? syntax error 55.55 10 10 55.55 55.55
Class A
{
public:
A(int n)
{
cout<<n;
}
};
class B:public A
{
B(int n,double d):A(n)
{
cout<<""<<d;
}
};
int main()
{
B b(10 ,55.55);
return 0;
}
104 What will be the output of the following 10 A 11.11 A 11.11 10 A 11.11
code?
Class A
{
public:
A(int x)
{
cout<<x;
}
};
class B: public A
{
public:
B(int x,char y):A(x)
{
cout<<" "<<y;
}
};
class C:public B
{
public:
C(int x,char y,double z) :B(x,y)
{
cout<<" "<<z;
}
};
int main()
{
C c(10,'A’,11.11);
return 0;
}
105 When an object of derived class is instantiated base class constructor derived class constructor not allowed to instantiate none of these
the _ is called explicitly or implicitly. derived class constructor
106 Class b is derived from class A then it is Single inheritance Multiple inheritance Multilevel inheritance Hybrid inheritance
called____
107 Class C is derived from class B and class B is Single inheritance Multiple inheritance Multilevel inheritance Hybrid inheritance
derived from class A then it is called .
108 Class D is derived from class Base 1 and Single inheritance Multiple inheritance Multilevel inheritance Hybrid inheritance
Class Base 2 then it is called _ _.
109 Class A,B,ansC are derived from class Single inheritance Multiple inheritance Multilevel inheritance Hybrid inheritance
Base2then it is called __ .
110 What will be the output of the following 100 0 syntax error none of these
code?
class A
{
private:
int x;
protected:
int y;
public:
int z;
};
class B:public A
{
};
int main()
{
B b;
b.x=100;
cout<<b.x;
return 0;
}
111 When base class is derived in protected mode only 1 ,5 only 2,4 only 1,6 only 2,6
then .
1. public members of base class become
private members of derived class.
2. public member of the base class become
proctected members of derived class
3. public members of base class become
public members of derived class.
4. protected members of base class become
proctected members of derived class.
5. protected members of base class become
private members of derived class.
6. protected members of base class become
public members of derived.
112 When deriving a class with public inheritance, Public, public Public, private public ,protected protected ,private
public members of the base class become
members of the derived class and protected
members of the base class become
members of the derived class.
113 If the class is derived using protected mode public members private members protected none of these
then public members of the base class become
_ of derived class.
114 If the class is derived using protected mode public members private members protected none of these
then protected members of the base class
become _ of derived class.
115 If the class is derived using protected mode public members private members protected none of these
then private members of the base class
become _ of derived class.
116 What will be the output of the following x=10,y=20,z=30 error for x,y=20,z=30 error for x and y,z=30 error for x,y and z
code?
class A
{
private:
int x;
protected:
int y;
public:
int z;
};
class B:protected A
{
public:
void display()
{
x=10;
y=20;
z=30;
}
};
117 If a class is derived using private mode then public members private members protected none of these
public members of base class become _ of
derived class.
118 If a class is derived using private mode then public members private members protected none of these
protected mode members of base class
become _ _ of derived class
119 If a class is derived using private mode then public members private members protected none of these
private mode members of base class become
_ _ of derived class
120 What will be the output of the following x=100,y=200,z=300 error for x,y=200,z=300 error for x and y,z=300 error for x,y and z
code?
class A
{
private:
int x;
protected:
int y;
public:
int z;
};
class B:private A
{
public:
void display()
{
x=100;
y=200;
z=300;
}
};
121 What will be the output of the following The value of x,y and z are error for assigment of x error for assignment of x error for accessibilty
code? assigned as 10,20,30 and y of display ()
class A respectively function
{
private:
int x;
protected:
int y;
public:
int z;
void display()
{
x=10;
y=20;
z=30;
}
};
class B:private A
{
};
int main()
{
B b;
b.display();return 0;
}
122 During class inheritance if the visibility mode public private protected none of these
of derivation is not specified then the default
visibility mode is _ .
123 What is the difference between protected and private member is not protected member is both are inheritable but both are inheritable
private access specifier ? inhertiable and not inheritable and also private is accessible inthe but protected is not
accessible in derived accessible in derived class derived class accessible in the
class derived class.
124 If a derived class is struct then its visibiltiy public private protected . cannot inherit
mode is _ . structure
125 The constructors for both derived and base only the constructor of only the constructor of the constructor of base the constructor of
class are defined .using the main the object off derived class will be base class will be invoked. class will be invoked and derived class will be
derived class is created . invoked then the constructor of invoked and then the
In such a situation _. derived class will be constructor of base
invoked class will be invoked
126 What will be the output of the following base class constructor derived class constructor base class constructor derived class
code? derived class constructor constructor base
class A class constructor
{
public:
A()
{
cout<<"base class
construtor";
}
};
class B:public A
{
public:
B()
{
cout<<"Derived Class
Constructor";
}
};
int main()
{
B b;
return 0;
}
127 If we define a base class constructor with optional compusory depends upon the it will generate
arguments then it is _ for derived class to compiler syntax error because
have constructor and pass argument to base paramerized
class constructor. constructor is not
allowed in base class
128 What will be the output of the following . B_constructor B_constructor B_constructor Run time error
code? D_constructor D_constructor B_destructor
Class A D_destructor B_destructor D_constructor D_
129 Which of the following is/are valid ways . int *p = new int(100); int *p; p = new int; *p = int *p = NULL; p = All of these
to allocate memory for an integer by 100; new int; *p=100;
dynamic memory allocation in CPP?
130 During dynamic memory allocation in False NULL Zero None of these
CPP, new operator returns _
value if memory allocation is
unsuccessful.
131 When the memory spaces for the member when the objects are when the class are when member All of these
functions are allocated? created created functions are defined as
a part of class
132 Why separate memory locations are member variables hold each object in the class Both a,b none of these
essential for an object different data values for has separate member
different objects function
133 The amount of memory allocated for an amount of memory amount of memory amount of memory amount of memory
object is equal to required by member required by data required by both data required by the
functions of that class members of that class members and data class
functions
134 All the objects of a class share the same data members member functions both data members and None of these
copy of member function
135 How will you free the memory allocated delete(p) delete p delete(int p) delete (p,0)
by the following program?
#include <iostream>
using namespace std
int main()
{
int *p;
p=new int;
return 0;
}
136 When the memory spaces for the data when the class is when the object of the when the member None of these
member are allocated? specified class is declared function is declared
137 How much memory will be allocated to 8Bytes 7Bytes 6Bytes No memory will
the object obj1 of the following class? be allocated
class test
{
float a;
int b;
char c;
}
int main()
{
test obj1;
return 0;
}
138 What are arrays in the C++? . A series of elements A series of elements of A series of elements of A series of
of same type placed in different type placed in same type placed in elements of
continuous block of continuous block of non-continuous block different type
memory. memory of memory placed in non-
continuous block
of memory.
139 The memory address for array can be a[0] address_of(a) a[1] a
obtained using _ _.
140 Which of the following are characteristics The array contains all All the elements of the The name of the array All of the above
of array? the elements of same array share the same represents the address
data type name and then can be of the first element of
distinguished from one an array
another by index
141 How will you pass the large objects in using call by value using call by reference either a or b none of these
C++? method method
142 Which of the following correctly declares int array[10]; int array; array{10}; array array[10];
an array?
143 What is the index number of the last 9 8 0 Programmer-
element of an array with 9 elements? defined
144 The process of storing the elements in an initialization of array declaration of array finalization of array none of the above
array is called as
145 Which of the following correctly declares ABC array[10]; ABC array; array{10}; array array[10];
an array of objects for a class ABC?
146 How much memory will be allocated to 10Bytes 20Bytes 40Bytes No memory is
the object obj1 in the following code? allocated
#include<iostream>
using namespace std;
class student
{
int age;
int roll_no;
public:
………
....……
};
int main()
{
student s[10];
………..
………..
return 0;
}
147 What will be the output of the following 30and3 0and0 11and 22 22and11
code?
vector vector::operator+(vector obj)
{
vector temp;
temp.p=p+obj.p;
temp.q=q+obj.q;
return (temp);
}
int main()
{
vector a(10,20);
vector b(1,2);
vector c;
c=a+b;
cout<<c.p<<”and”<<c.q;
return 0;
}
148 Which of the following statements are only 1 and 2 only 3 and 4 All of the above None of the above
true for operator overloading?
1. Only existing operators can be
overloaded
2. The overloaded operator must have at
least one operand that is of user defined
type.
3. Overloaded operators follow the syntax
rules of the original operators.
4. Binary arithmetic operators such as +,-
,* and / must explicitly return a value.
149 Which is the correct function prototype complex complex complex complex
declaration for overloading the ‘+’ operator+(complex); operator++(complex); operator+(complex) operator(complex);
operator in class ‘complex’?
150 Inheritance is ............... in nature. Intransitive Transitive Both (a) & (b) None of the above
151 The result of the following statement is ans=7, y=7 ans=8,y=7 ans=8,y=8; none of the above
int y = 7;
int ans = ++y;
cout<<”ans=”<<ans;
cout<<”y”<<y;
152 What is the output of the following code? Error The result of addition The result of addition The result of
#include<iostream> is:16 is:sum(); addition is:
using namespace std;
class test
{
int a,b;
public:
test(int x, int y)
{
a=x; b=y;
}
int sum();
void display();
};
int test::sum()
{
return a+b;
}
void test::display()
{
cout<<”\nThe result of addition
is:”<<sum();
}
void main()
{
test obj1(7,9);
obj1.display();
return 0;
}
153 A constructor function is ___ A friend function to a A member function with A non-member None of the above
class the same name as its function
class
154 A constructor function is generally In the public section of In the private section of In the protected section None of the above
defined __ a class a class of a class
155 A class having no public constructors is A private class A public class An abstract class None of the above
__
156 If a constructor function is defined in The object cannot be Only member functions Both (a) & (b) None of the above
private section of a class, then created and friends may declare
__ objects of the class
157 A constructor with no argument is Default constructor Parameterized Copy constructor None of the above
__ _ constructor
158 If arguments are provided to a constructor Default constructor Copy instructor Parameterized None of the above
159 The parameterized constructor Needs initial values as Can be invoked Can be invoked None of the above
__ arguments during explicitly only implicitly only
creation of an object
160 Given a class named Book, which of the Book ( ) { } Book ( Book b) { } Book ( Book &b) { } Book (char*
following is not a valid constructor? author, char* title)
{}
161 Which of the following statements A constructor may be Constructor can have Member functions may None of the above
regarding constructor is false? defined static default arguments be invoked from within
a constructor
162 A destruction function Takes no argument and Has name similar to that Is used to destruct an All of the above
has no return type not of class, preceded by object, constructed
even void tilde(~) symbol through constructor
function
163 Destructors are called __ _ in the same order of in the reverse order of in any random order none of the above
constructor calls constructor calls
164 Constructors are used _ to build a user interface deallocate memory initialize newly created to construct
objects functions
165 If a default constructor is not defined then it will cause syntax ) it will cause runtime the complier will create none of these
__ . error error constructor for creating
an object
166 How many constructors can a class have? 0 1 2 any number
167 Which of the following is not the They should be They do not have return They can not be They can be
characteristic of constructor. declared in the public type. inherited virtual.
section.
168 In which case is it mandatory to provide a Almost in every class Class for which two or Class for which copy Class whose
destructor in a class? more than two objects constructor is defined objects will be
will be created created
dynamically
169 Class function which is called Constructor Destructor Friend function Inline function.
automatically as soon as the object is
created is called as __
170 Complement of the constructor is Overloading Inheritance Polymorphism Destructor
171 If c1 and c2 are objects of class complex Sum is : 12+i2 Sum is : 5+i4 Sum is : 7-i2 syntax error
and c1=5+i4 and c2=7-i2 then what is the
output of the following program?
#include <iostream>
#include <math.h>
using namespace std;
class complex
{
int real,img;
public:
void display()
{
if(img>0)
cout<<real<<"+i"<<img<<endl;
else
{
cout<<real<<"-i"<<-
img<<endl;
}
}
complex operator+(complex);
};
complex complex :: operator+(complex c2)
{
complex sum;
sum.real = real+c2.real;
sum.img = img+c2.img;
return (sum);
}
int main()
{
complex c1,c2,ans;
ans = c1+c2;
cout<<"Sum is : ";
ans.display();
return 0;
}
172 An array name is a _____ Subscript formal parameter memory address prototype
174 Declaration of a pointer reserves memory for the object for the pointer both for the object and None of these.
space the pointer
175 Identify the operator that is NOT used -> & * >>
with pointers
176 An array element is accessed using a FIFO approach an index number the operator member name
177 The address of a variable temp of type *temp &temp float& temp float temp&
float is
178 Identify the correct sentence we cannot create the we can create the Array we can use reference to none of the
regarding inequality between reference array of reference. of reference reference mentioned
and pointer.
179 Functions can return_ _ Arrays References Objects All of above
1. Which of the following term is used for a function defined inside a class?
A. Member Variable
B. Member function
C. Class function
D. Classic function
14. ‘cin’ is __
A –a Class
B - an Object
C –a Package
D – Namespace
15. With respect to streams >> (operator) is called as __________
A - Insertion operator
B - Extraction operator
C - Right shift operator
D - Left shift operator
16. In C++, by default all members are ........ in a struct and ........ in a class .
A - public , private
B - public , public
C - private , public
D - private , private
18. 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.
19. Which of the following keywords is used to control access to a class member?
A-Default
B-Break
C-Protected
D-Asm
20. 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.
public:
inti;
abc(inti) {
i = i;
}
};
main() {
abc m(5);
cout<<m.i;
return 0;
}
A-5
B - Garbage
C - Error at the statement i=i;
D - Compile error: ‘i’ declared twice.
m = n;
n = x;
}
main() {
int x = 5, y = 3;
swap(x,y);
cout<<x<<" "<<y;
return 0;
}
A-35
B-53
C-55
D - Compile error
27. How much memory will be allocated to object obj1 in following code?
#include<iostream>
using namespace std;
Class ABC
{
int x;
char y;
public:
void getdata();
};
main()
{
ABC obj1;
}
A-1 Byte
B-2Bytes
C-3 Bytes
D- 4 Bytes
29. Everything defined at the program scope level (ie. outside functions and classes) is said to be _______
A) local scope
B) regional scope
C) global scope
D) static scope
41. The memory required by any objects is dependent upon following factors
A. size of non static data members of the class
B. order of data members
C. Byte padding
D. all of these
45.The constructors and destructors for objects are automatically invoked ____.
A. by making explicit call to constructor and destructor functions
B. when object enters and leaves its scope.
C. when inheritance occurs
D. none of these
Multiple choice question bank on topic defining member functions, making outside
function inline, nesting of member functions, private member functions
4. A member function can be called by using its name inside another member function of
the same class is called as
a) Inline function
b) Member function
c) Nesting of member function
d) Public member function
#include <iostream>
using namespace std;
classabc
{
private:
int array1[5]={0,2,4,8,5};
public:
void compute();
};
voidabc ::compute()
{
int result=0;
for(inti=0;i<5;i++)
{
result=result+array1[i];
}
cout<< result;
}
int main()
{
abc x;
x.compute();
return 0;
}
a) 19
b) 20
c) Garbage value
d) Syntax error
18. Which of the following keywords are used to control access to a class member?
a) default
b) break
c) protected
d) goto
19. If function is defined outside the class, its prototype declaration must be
a ) inside class
b) outside class
c) botha&b
d) None of the above
#include <iostream>
using namespace std;
class A
{
int c;
void add (int a, int b)
{
c=a+b;
cout<<"c="<<c;
}
};
int main()
{
A a;
a.add(5,7);
return 0;
}
a) 12
b) Error
c) 18
d) None of the above
#include <iostream>
using namespace std;
class B
{
public:
void main()
{
cout<<endl<<"In member function main()";
}
};
int main()
{
B b;
b.main();
return 0;
}
22. which of the following is true while defining member function outside the class
1) return_typeclass_name :: member_function() {}
2)class_name ::return_typemember_function() {}
a) 1 true
b) 2 true
c) 1 & 2 both are true
d) both are false
26. Which of the following parameter passing mechanism is/are supported by C++ but not in C?
[A] Pass by value
[B] Pass by reference
[C] Pass by value result
[D] All of the above
27. Which of the following type of function is an ideal candidate for being declared inline ?
[A] A function that is small and is not called frequently
[B] A function that is small and is called frequently
[C] A function that is not small and is not called frequently
[D] A function that is not small and is called frequently
31. A variable is defined within a block in a body of a function. Which of the following are true
?a. It is visible from the point of definition to the end of the program.
b. It is visible throughout the function.
c. It is visible from the point of definition to the end of the block.
d. It is visible throughout the block.
8) Given a class named Book, which of the following is not a valid constructor?
(A) Book ( ) { }
(B) Book ( Book b) { }
(C) Book ( Book&b) { }
(D) Book (char* author, char* title) { }
class test
{
private:
int a;
public:
test()
{
a=0;
cout<<"constructor";
}
~test()
{
cout<<"destructor";
}
};
int main()
{
test a[2];
return 0;
}
a) constructorconstructordestructordestructor
b) constructordestructor
c) constructorconstructor
d) no output
class test
{
public:
test()
{cout<< "constructor";}
~test()
{cout<< "destructor";}
};
int main()
{
delete new test();
return 0;
}
a) syntax error
b) nothing will be displayed
c) constructor destructor
d) constructorconstructor
19. Class function which is called automatically as soon as the object is created is called as __
A - Constructor
B - Destructor
C - Friend function
D - Inline function.
21. The destructor has the same name as the constructor, but is preceded by a
A - '~'
B - '-'
C - '^'
D - '::'
22. A Constructor that does not have any parameters is called____________ Constructor.
a. Custom
b. Dynamic
c. Static
d. Default
a. Only 1,2,4
b. 1,2,4,5
c. 1,3,5
d. 1,4,5
24.If default constructor is not defined, then how the objects of the class will be created?
a. The compiler will generate error
b. Error will occur at run-time.
c. Compiler provides its default constructor to build the object.
d. None of these
29. If ‘Student’ is the name of the class, then which of the following constructor declaration in
class is correct?
a. Student(){}
b. Student(){};
c. Student::Student(){};
d. none of the above
30. A class is not having default constructor but o ne parameterized constructor. We have created
an object that needs zero argument constructor. What will happen in this case?
a. The desired object will get created because compiler will create an implicit default constructor
b. It will cause syntax error
c. It will cause runtime error
d. None of these
Operator Overloading
1. While overloading binary operators using member function, it requires ___ argument/s.
a. Zero
b. One
c. Two
d. Three
2. In case of binary operator overloading with member function, which of following statement
should be taken into consideration?
A. Right hand operand must be object.
B. Left hand operand must be object.
C. Both the operands must be objects.
D. All of these should be considered.
a. <iomanipulator.h>
b. <stdiomanip.h>
c. <stdmanip.h>
d. <iomanip.h>
a. iterator
b. allocator
c. constructor
d. operator
6) Operator overloading is
a. technique to work with objects
b. technique which allows C++ to handle more than one operator
c. making new C++ operators
d. giving new relevant meaning to existing c++ operators without changing basic meaning
7) Which of the following is the perfect set of operators that can’t be overloaded in CPP ?
a. +=, ?, :: , >>
b. >>, <<, ?, *, sizeof()
c. :: , . , .* , ?:
d. :: , ->, * , new, delete
8) new operator is used
a) to define a new variable
b) to create a new data type
c) to allocate memory dynamically
d) none of the above
11. Which of the following statements is NOT valid about operator overloading?
(A) Only existing operators can be overloaded.
(B) Overloaded operator must have at least one operand of its class type.
(C) The overloaded operators follow the syntax rules of the original operator.
(D) none of the above.
13) The function that overloads as operator, precedes with the keyword
a) function
b) operator
c) virtual
d) static
17. When using binary operators overloaded through a member function, the left hand operand
must be__________ of the relevant class.
a. data member
b. an object
c. a variable of the member function
d. none of the above.
18. Which of the following statements are true for operator overloading?
1. Only existing operators can be overloaded
2. The overloaded operator must have at least one operand that is of user defined type.
3. Overloaded operators follow the syntax rules of the original operators.
4. Binary arithmetic operators such as +,-,* and / must explicitly return a value.
a. only 1 and 2
b. only 3 and 4
c. All of the above
d. None of the above
19. Which is the correct function prototype declaration for overloading the ‘+’ operator in class
‘complex’?
a. complex operator+(complex);
b. complex operator++(complex);
c.complex operator+(complex)
d.complex operator(complex);
20. If c1 and c2 are objects of class complex and c1=5+i4 and c2=7-i2 then what is the output of
the following program?
#include <iostream>
#include <math.h>
using namespace std;
class complex
{
intreal,img;
public:
void display()
{
if(img>0)
cout<<real<<"+i"<<img<<endl;
else
{
cout<<real<<"-i"<<-img<<endl;
}
}
complex operator+(complex);
};
complexcomplex :: operator+(complex c2)
{
complex sum;
sum.real = real+c2.real;
sum.img = img+c2.img;
return (sum);
}
int main()
{
complex c1,c2,ans;
ans = c1+c2;
cout<<"Sum is : ";
ans.display();
return 0;
}
a. Sum is :12+i2
b. Sum is :5+i4
c. Sum is :7-i2
d. syntax error
Inheritance
a) Inheritance
b) Overloading
c) Polymorphism
d) None of the above
a) ans=7, y=7
b) ans=8,y=7
c) ans=8,y=8;
d) none of the above
9) Inheritance is referred to as
a) “is a” relationship
b) “has a” relationship
c) Both (a) & (b)
d) none of the above
11) If a class C is derived from class B, which is derived from class A, all through public
inheritance, then a class C member function can access
(A) protected and public data only in C and B.
(B) protected and public data only in C.
(C) private data in A and B.
(D) protected data in A and B.
a) 3100
b) 3010
c) 2010
d) 1010
15. The process of building new classes from existing one is called
(A) Structure.
(B) Inheritance.
(C) Polymorphism.
(D) Template.
16. Consider the following class definitions:
class a
{
};
class b: protected a
{
};
What happens when we try to compile this class?
(A) Will not compile because class body of a is not defined.
(B) Will not compile because class body of b is not defined.
(C) Will not compile because class a is not public inherited.
(D) Will compile successfully.
19. In case of inheritance where both base and derived class are having constructors, when an object of
derived class is created then___________
A. constructor of derived class will be invoked first
B. constructor of base class will be invoked first
C. constructor of derived class will be executed first followed by base class
D. constructor of base class will be executed first followed by derived class
20. What is the difference between protected and private access specifiers in inheritance?
A. private member is not inheritable and not accessible in derived class.
B. protected member is inheritable and also accessible in derived class.
C. Both are inheritable but private is accessible in the derived class.
D. Both are inheritable but protected is not accessible in the derived class.
21. When a base class is privately inherited by the derived class, then_____________ .
A. protected members of the base class become private members of derived class
B. public members of the base class become private members of derived class
C. both a and b
D. only b
22. The derivation of Child class from Base class is indicated by ____ symbol.
A. ::
B. :
C. ;
D. |
23.During a class inheritance in CPP, if the visibility mode or mode of derivation is not
provided, then by default visibility mode is ___________.
A. public
B. protected
C. private
D. Friend
27. Class C is derived from class B and class B is derived from class A then it is called ____.
A. Single inheritance
B. Multiple inheritance
C. Multilevel inheritance
D. Hybrid inheritance
28. Class D is derived from class Base1 and class Base2 then it is called ____.
A. Single inheritance
B. Multiple inheritance
C. Multilevel inheritance
D. Hybrid inheritance
29. Class B and C are derived from class A and class D is derived from class B and C, then it is
called _____.
A. Single inheritance
B. Multiple inheritance
C. Multilevel inheritance
D. Hybrid inheritance
32. When deriving a class with public inheritance,public members of the base class become____
members of the derived class and protectedmembers of the base class ___ become members of
the derived class.
A. public public
B. public private
C. public protected
D. protected private
33. If the class is derived using protected mode then public members of the base class become
___ of derived class.
A. public members
B. private members
C. protected
D. none of these
34. If the class is derived using protected mode then protected members of the base class become
___ of derived class.
A. public members
B. private members
C. protected
D. none of these
35. If the class is derived using protected mode then private members of the base class become
___ of derived class.
A. public members
B. private members
C. protected
D. no access
class A
{
private:
int x;
protected:
int y;
public:
int z;
};
class B:protected A
{
public:
void display()
{
x=10;
y=20;
z=30;
}
};
A. x=10,y=20,z=30
B. error for x,y=20,z=30
C. error for x and y,z=30
D. error for x,y and z
37. If a class is derived using private mode then public members of base class become ___ of
derived class.
A. public members
B. private members
C. protected
D. none of these
38. If a class is derived using private mode then protected mode members of base class become
____ of derived class
A. public members
B. private members
C. protected
D. none of these
39. If a class is derived using private mode then private mode members of base class become
____ of derived class
A. public members
B. private members
C. protected
D. no access
class A
{
private:
int x;
protected:
int y;
public:
int z;
void display()
{
x=10;
y=20;
z=30;
}
};
class B:private A
{
};
int main()
{
B b;
b.display();
return 0;
}
A. The value of x,y and z are assigned as 10,20,30 respectively
B. error for assignment of x
C. error for assignment of x and y
D. error for accessibility of display () function
42. What is the difference between protected and private access specifier?
A. private member is not inheritable and not accessible in derived class.
B. protected member is inheritable and also accessible in derived class.
C. both are inheritable but private is accessible inthe derived class.
D. both are inheritable but protected is not accessible in the derived class.
class A
{
public:
A()
{
cout<<"base class constructor";
}
};
class B:public A
{
public:
B()
{
cout<<"Derived Class Constructor";
}
};
int main()
{
B b;
return 0;
}
A. base class constructor
B. base class constructor derived class constructor
C. base class constructorDerived class constructor
D. derived class constructor base class constructor
44. If we define a base class constructor with arguments then it is ___ for derived class to have
constructor and pass argument to base class constructor.
A. optional
B. compulsory
C. depends upon the compiler
D. it will generate syntax error because parameterized constructor is not allowed in base class
Arrays
6. What is the index number of the last element of an array with 9 elements?
a) 9
b) 8
c) 0
d) Programmer-defined
9) How much memory will be allocated to the object obj1 in the following code?
#include<iostream>
using namespace std;
class student
{
int age;
introll_no;
public:
………
....……
};
int main()
{
student s[10];
………..
………..
return 0;
}
a. 10Bytes
b. 20Bytes
c. 40 Bytes
d. No memory is allocated
ONLINE QUESTIONS
a. calloc()
b. malloc()
c. allocate
d. New
2) Which of the following operator is used to release the dynamically allocated memory in C++?
a. remove
b. free
c. delete
d. both b and c
3) Which of the following is/are valid ways to allocate memory for an integer by dynamic
memory allocation in CPP?
4) During dynamic memory allocation in CPP, new operator returns _________ value if
memory allocation is unsuccessful.
a. False
b. NULL
c. Zero
d. None of these
5) When the memory spaces for the member functions are allocated?
a) data members
b) member functions
c) both data members and member function
d) None of these
9) How will you free the memory allocated by the following program?
#include <iostream>
using namespace std
int main()
{
int *p;
p=new int;
return 0;
}
a) delete(p)
b) delete p
c) delete(int p)
d) delete (p,0)
10) When the memory spaces for the data member are allocated?
a) when the class is specified
b) when the object of the class is declared
c) when the member function is declared
d) None of these
11) How much memory will be allocated to the object obj1 of the following class?
class test
{
float a;
int b;
char c;
}
int main()
{
test obj1;
return 0;
}
a. 8Bytes
b.7Bytes
c. 6Bytes
d. No memory will be allocated
MCQs on Unit 4
8. Which problem may arise if we use abstract class functions for polymorphism?
a) All classes are converted as abstract class
b) Derived class must be of abstract type
c) All the derived classes must implement the undefined functions
d) Derived classes can’t redefine the function
9. When the inheritance is private, the private methods in base class are __________ in the derived class
(in C++).
A. Inaccessible
B. Accessible
C. Protected
D. Public
class student
{
public :
int marks;
void disp()
{
cout<<”its base class”;
};
class topper:public student
{
public :
void disp()
{
cout<<”Its derived class”;
}
}
void main() { student s; topper t;
s.disp();
t.disp();
}
A. its base class its derived class
B. its base class its derived class
C. its derived class it’s base class
D. none of these
16. Run time polymorphism is achieved only when a ……………….. Is accessed through a
pointer to the base class.
A) static function
B) Real function
C. Member function
D) Virtual function
1. Function overriding
2. Operator overloading
3. A&B
4. None
18. In case of inheritance where both base and derived class are having constructor and
destructor, then which if the following are true ?
class R: public Q { };
int main(void)
{
R r;
r.print();
return 0;
}
(A) Inside P
(B) Inside Q
(C) Compiler Error: Ambiguous call to print()
(D) None of the above
#include<iostream>
using namespace std;
int main()
{
Base *bp = new Derived;
Derived *dp = new Base;
}
Class Q subclass of P
{ void f(int i)
{ print(2*i); }
}
Now consider the following program fragment:
P x = new Q();
Q y = new Q();
P z = new Q();
x.f(1); ((P)y).f(1); z.f(1);
Here ((P)y) denotes a typecast of y to P. The output produced by executing the above
program fragment will be
(A) 1 2 1
(B) 2 1 1
(C) 2 1 2
(D) 2 2 2
A. “Private” elements of a base class are not accessible by members of its derived class.
B. “Protected” elements of base class are not accessible by members of its derived
class.
C. When base class access specified is “Public”, public elements of the base class become
public members of its derived class.
D. When base class access specified is “Public”, protected elements of a base class become
protected members of its derived class.
24. Which of the following is true?
(A) A “static” member of a class cannot be inherited by its derived class.
(B) A “static” member of a class can be initialized only within the class it is a member of.
(C) A “static” member of a class can be initialized before an object of that class is created.
(D) Since a “static” member of a class is actually a global element, it does not require a
class/object qualifier to access it independently of class/object.
25. Assume that we have constructor functions for both base class and derived class. Now
consider the declaration in
main()
26. If a class C is derived from class B, which is derived from class A, all through public
inheritance, then a class C member function can access
27. Which of the following is/are correct with reference to Abstract class and interface?
a. A class can inherit only one Abstract class but may inherit several interfaces
b. An abstract class can provide complete and default code but an interface has no code
A. a is true
B. b is true
C. Both a and b are true
D. Neitehr a nor b are true
28. Which of the following is/are correct with reference to Abstract class and interface?
a. A class can inherit only one Abstract class but may inherit several interfaces
b. An abstract class can provide complete and default code but an interface has no code
A. a is true
B. b is true
C. Both a and b are true
D. Neither a nor b are true
30. Which of the following differentiates between overloaded functions and overridden functions
?
A. Derived values
B. Default type values
C. Both default type & derived values
D. None of the above
2. What is a template?
3. Which of the following best defines the syntax for template function ?
4. Templates are abstract recipe for producing a concrete code, and it is used for
A. Producing functions
B. Producing classes
C. Nothing
D. Both A and B
5.How many parameters are legal for non-type template?
A. 1
B. 2
C. 3
D. 4
A. 1
B. 2
C. 3
D. 4
A. Yes
B. No
C. May Be
D. Can't Say
A. Containers
B. Functions
C. Strings
D. None of the above
A. Functions
B. Non virtual member function
C. Member class
D. All of the above
A. conditional operator
B. ternary operator
C. scope operator
D. None of the mentioned
14. What is the general syntax for accessing the namespace variable?
A. namespace::operator
B. namespace,operator
C. namespace#operator
D. namespace$operator
A. TRUE
B. FALSE
C. May Be
D. Can't Say
16. Which of the following is correct option?
A. 43.5478
B. 43
C. 44
D. 30
A. Try
B. Throw
C. Catch
D. None of the above
19. Which is used to throw a exception?
A. Try
B. Throw
C. Catch
D. None of the above
A. bad_cast
B. bad_typeid
C. bad_exception
D. bad_alloc
22. In nested try block, if inner catch handler gets executed, then __________?
A. int
B. bool
C. char *
D. double
24. Which of the following statements are true about Catch handler? i) It must be placed
immediately after try block T. ii) It can have multiple parameters. iii) There must be only
one catch handler for every try block. iv) There can be multiple catch handler for a try
block T. v) Generic catch handler can be placed anywhere after try block.
A. Only i, iv, v
B. Only i, ii, iii
C. Only i, iv
D. Only i, ii
25. If inner catch handler is not able to handle the exception then__________ .
27. The code of statements which may cause abnormal termination of the program should be
written under_________ block.
a. Try
b. catch
c. Finally
d. None of these
28. Which of the following statements are true about Catch handler?
1. It must be placed immediately after try block T.
2. It can have multiple parameters.
3. There must be only one catch handler for every try block.
4. There can be multiple catch handler for a try block T.
5. Generic catch handler can be placed anywhere after try block.
a. Only 1, 4, 5
b. Only 1, 2, 3
c. Only 1, 4
d. Only 1, 2
33. Which of the following best defines the syntax for template function ?
a. template return_type Function_Name(Parameters)
b. template return_type Function_Name(Parameters)
c. Both A and B
d. None of the above
34. Templates are abstract recipe for producing a concrete code, and it is used for
a. Producing functions
b. Producing classes
c. Nothing
d. Both A and B
namespace A{
int var = 10;
namespace B{
int i = 15;
}
}
a) cout<<A::i;
b) cout<<B::i;
c) cout<<A::B::i;
d) cout<<i;
43. Irrespective of exception occurrence, catch handler will always get executed.
a)True
b)False
45. Functions called from within a try block may also throw exception.
a) True
b) False
a) conditional operator
b) ternary operator
c) scope operator
d) None of the mentioned
49. What is the general syntax for accessing the namespace variable?
a) namespace::operator
b) namespace,operator
c) namespace#operator
d) namespace$operator
#include <iostream>
#include <typeinfo>
int main ()
try
Polymorphic * pb = 0;
typeid(*pb);
catch (exception& e)
return 0;
54. What will happen when a programs throws any other type of exception other than
specified?
a) terminate
b)arise error
c)run
d)throw
60. What is the general syntax for accessing the namespace variable?
a) namespace::operator
b) namespace,operator
c) namespace#operator
d) namespace$operator
#include<iostream>
namespace lfc1
{
namespace lfc2
int main ()
int a;
a = lfc1::var + lfc2::var;
cout << a;
return 0;
}
a)43.54
b)43
c)44
d)30
#include <iostream>
int main()
try
throw 'b';
}
catch (int param)
catch (...)
return 0;
c) Int Exception
d) Default Exception
K.K. Wagh Institute of Engineering Education and Research, Nashik
SE (E&TC)
Object Oriented Programming
3. Which function is used in C++ to get the current position of file pointer in a file?
a) tell_p()
b) get_pos()
c) get_p()
d) tell_pos()
A. Returns true if a file open for reading has reached the next character.
B. Returns true if a file open for reading has reached the next word.
C. Returns true if a file open for reading has reached the end.
D. Returns true if a file open for reading has reached the middle.
{
FILE *fp;
char x[1024];
fp = fopen("find.txt", "r"); // "ayushjain and prateek"
x[0] = getc(fp);
fseek(fp, 0, SEEK_END);
fseek(fp, -7L, SEEK_CUR);
fgets(x, 6, fp);
puts(x);
return 0;
}
A. ayushj
B. yushja
C. ayushja
D. prate
9. The __________ built in class can be used to create files and read information
from them into memory.
A. instream
B. ifstream
C. ofstream
D. istream
12. In fopen(), the open mode "wx" is sometimes preferred "w" because. i)
Use of wx is more efficient. ii) If w is used, old contents of file are erased and
a new empty file is created. When wx is used, fopen() returns NULL if file
already exists.
A. Only i
B. Only ii
C. Both i & ii
D. None of the above
13. To perform File I/O operations, we must use _____________ header file.
A. < ifstream>
B. < ofstream>
C. < fstream>
D. Any of these
16. In order, the three-step process of using a file in a C++ program involves:
A. Name the file, open the file, and delete the file
B. Insert a diskette, open a file, and remove the disk
C. Open the existing file, read/write data, close the file
D. Create the file contents, close the file, and name the file
17. Which of the following is used to Open a file for output and move the
read/write control to the end of the file ?
A. ios::ate
B. ios::at
C. ios::ann
D. ios::end
A-Default
B-Break
C-Protected
D-Asm
Clear selection
2. Which of the following can access private data members or member functions
of a class?
1 point
Clear selection
Clear selection
A- member function
B- a class function
C- in built
D- none of above
Clear selection
A- :
B- ;
C-#
D-$
Clear selection
A. polymorphism
B. dimorphism
C. trimorphism
D. none of these
Clear selection
A. classes
B. inheritence
C. polymorphism
D. dimorphism
Clear selection
A) static function
B) Real function
C. Member function
D) Virtual function
Clear selection
A. polymorphism
B. multipath inheritance
C .hierarchical inheritance
D. none of these
Clear selection
10. The two or more classes serve as base class for a derived class, then this
situation is called .
1 point
A. Polymorphism
B. multiple inheritance
C. encapsulation
D. none of these
Which datatype is used to represent the absence of parameters? (CO1)
1 point
a) int
b) short
c) void
d) float
Clear selection
a) enumeration
b) classes
c) both a and b
d) int
a) protected
b) switch
c) goto
d) for
A) :
B) ::
C) #
D) None Of The Mentioned
A - Insertion operator
B - Extraction operator
C - Right shift operator
D - Left shift operator
a) Overloading ||
b) Overloading +=
c) Overloading <<
d) Overloading &&
A. Dynamic binding
B. Polymorphism
C. Both Dynamic binding & Polymorphism
D. None of the mentioned
A. Functions
B. Non virtual member function
C. Member class
D. All of the above
10. To perform File I/O operations, we must use _____________ header file.
1 point
A. < ifstream>
B. < ofstream>
C. < fstream>
D. Any of these
Pimpri Chinchwad Education Trust’s
Pimpri Chinchwad College of Engineering
Sector No. 26, Pradhikaran,
Nigdi, Pune – 411 044
a) Overriding the operator meaning by the user defined meaning for user defined data type
c) Ability to provide the operators with some special meaning for user defined data type
a) A operator+(argument_list){}
b) A operator[+](argument_list){}
c) int +(argument_list){}
d) int [+](argument_list){}
a) 1
b) 2
c) 3
d) 4
a) +
b) ?:
c) –
d) %
a) ?:
b) ::
c) .
d) ==
6.Which of the following operator cannot be used to overload when that function is declared as
friend function?
a) -=
b) ||
c) ==
d) []
7. Which of the following operator can be used to overload when that function is declared as
friend function?
a) []
b) ()
c) ->
d) |=
8.In case of non-static member functions how many maximum object arguments a unary operator
overloaded function can take?
a) 1
b) 2
c) 3
d) 0
9.In case of non-static member functions how many maximum object arguments a binary
operator overloaded function can take?
a) 1
b) 2
c) 3
d) 0
10. In the case of friend operator overloaded functions how many maximum object arguments a
unary operator overloaded function can take?
a) 1
b) 2
c) 3
d) 0
A. .* (Pointer-to-member Operator )
C. .* (Pointer-to-member Operator )
13.While overloading binary operators using member function, it requires ___ argument?
A. 2
B. 1
C. 0
D. 3
14.Which of the following operators should be preferred to overload as a global function rather
than a member method?
A. Postfix ++
B. Comparison Operator
D. prefix ++
15. Which of the following operator functions cannot be global, i.e., must be a member function.
A. new
B. delete
C. Converstion Operator
D. All of the above
16.In case of operator overloading, operator function must be ______ . 1. Static member
functions 2. Non- static member functions 3. Friend Functions
a. Only 2
b. Only 1, 3
c. Only 2 , 3
d. All 1 , 2, 3
d. None of these
a. iterator
b. allocator
c. constructor
d. operator
A. 30
B. 40
C. 45
D.50
A. —
B. +
C. ++
D. Dereferencing operator(*)
21. The feature that allows you to use the same function name for separate functions that have
different argument lists is called _____
a. overriding
b. overloading
c. constructing
d. destructing
b) size of operator
c) conditional operator
a) implicitly
b) explicitly
a) unary
b) binary
c) ternary
c) The overloaded operator must have at least one operand that is of user-defined type.
29.Operator overloading is
30. In the following program f() is overloaded. void f(int x) { } int f(signed x) { return 1;} main()
{}
1 point
A - True
B - False
UNIT 4 MCQ
1. When the inheritance is private, the private methods in base class are __________ in the
derived class (in C++).
A. Inaccessible
B. Accessible
C. Protected
D. Public
Ans : A
Ans : A
Ans : C
4. What will be the order of execution of base class constructors in the following method of
inheritance.class a: public b, public c {...};
Ans : A
Answer: d
6. How many basic types of inheritance are provided as OOP feature?
a) 4
b) 3
c) 2
d) 1
Answer: a
Answer: b
8. Which among the following is correct for multiple inheritance?
a) class student{public: int marks;}s; class stream{int total;}; class topper:public student, public
stream{ };
b) class student{int marks;}; class stream{ }; class topper: public student{ };
c) class student{int marks;}; class stream:public student{ };
d) class student{ }; class stream{ }; class topper{ };
Answer: a
Answer: d
Answer: c
11. Which is the correct syntax of inheritance?
a) class derived_classname : base_classname{ /*define class body*/ };
b) class base_classname : derived_classname{ /*define class body*/ };
c) class derived_classname : access base_classname{ /*define class body*/ };
d) class base_classname :access derived_classname{ /*define class body*/ };
Answer: c
12. Which type of inheritance leads to diamond problem?
a) Single level
b) Multi-level
c) Multiple
d) Hierarchical
Answer: c
A. Operator overloading
B. Function overloading
C. Function overriding
D. B Only
E. A&B
Answer: E
Answer: D
A. Defining multiple functions with same name in a class is called function overloading
B. Overloaded function must differ in their order and types of arguments.
C. Overloaded functions should be preceded with virtual keyword
D. No statement is false
Answer: C
16 Following keyword is used before a function in a base class to be overridden in derived class in C++
A. override
B. virtual
C. void
D. none
Answer: B
A. Increment operator
B. Constructor
C. Destructor
D. New and delete operator
Answer: C
Answer - B
class student
{
public :
int marks;
1 class student
2 {
3 public :
4 int marks;
5 void disp()
6 {
7 cout<<”its base class”;
8 };
9 class topper:public student
10 {
11 public :
12 void disp()
13 {
14 cout<<”Its derived class”;
15 }
16 }
17 void main() { student s; topper t;
18 s.disp();
19 t.disp();
20 }
A. its base class its derived class
B. its base class its derived class
C. its derived class it’s base class
D. none of these
Answer - A
class education
{
char name[10];
public : disp()
1 class education
2 {
3 char name[10];
4 public : disp()
5 {
6 cout<<”Its education system”;
7 }
8 class school:public education
9 {
10 public: void dsip()
11 {
12 cout<<”Its school education system”;
13 }
14 };
15 void main()
16 {
17 school s;
18 s.disp();
19 } }
Answer -A
21. Using operation or function in different ways depending on what they are operating on
is called?
A. classes
B.inheritence
C. polymorphism
D. dimorphism
Answer - C
22. Run time polymorphism is achieved only when a ……………….. Is accessed through a
pointer to the base class.
A) static function
B) Real function
C. Member function
D) Virtual function
Answer - D
23. A class serves as base class for many derived classes it is called:
A. polymorphism
B. multipath inheritance
C .hierarchical inheritance
D. none of these
Answer -C
24. The two or more classes serve as base class for a derived class, then this situation is
called .
A. Polymorphism
B. multiple inheritance
C. encapsulation
D. none of these
Answer B
25. The problem may arise if we use abstract class functions for polymorphism in OOP?
A. All classes are converted as an abstract class
B. All the derived classes must implement the undefined functions
C. abstract class must have derived a class
D. Derived classes can’t redefine the function
Answer - C
Answer - D
Pimpri Chinchwad Education Trust’s
Pimpri Chinchwad College of Engineering
Sector No. 26, Pradhikaran,
Nigdi, Pune – 411 044
Q5 An object compromises of
A behaviour
B state
C none of both
D both of above d 1
Sr. Questions Ans Mark
No. s
Q6 Identify the incorrect statement
A A reference value once defined can be reassigned
B reference is the alternate name of the object
C A reference value once defined cannot be reassigned c 1
D none of the mentioned
Q7 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 public in structures but private in
classes.
C Member function and data are by default public in structures but protected in
classes
D Member function and data are by default private in structures but public in d 1
classes.
PTO
Sr. No. Questions Ans Marks
Q13 The feature of OOP that allows you to use the same function name for separate
functions that have different argument lists is called
A Overriding
B overloading b 1
C constructing
D Destructing
Q16 Which is used to tell the computer that where a pointer is pointing to?
A dereference a 1
B reference
C heap operations
D binary operations
int main()
{
cout << sizeof(Empty);
return 0;
}
A. A non-zero value
B. 0
C. Compiler Error
D. Runtime Error
6. The keywords private and public used in C++ are known as ………….
A) keyword labels
B) visibility labels
C) declaration labels
D) display labels
7. The variables declared inside the class are known as data members and functions are known as ………….
A) data functions
B) inline functions
C) member functions
D) member variables
8. When the function is defined inside a class, it is treated as ………………….
A) data function
B) inline function
C) member function
D) member variable
9. A ………………. member function can only be called by another function that is member of its class.
A) friend
B) static
C) public
D) private
10. Static variables are associated with the class itself rather than with any class object, they are also known as ………
A) class variables
B) object variables
C) function variables
D) internal variables
11. Static variables are like ………………… as they are declared in a class declaration and defined in the source file.
A) inline member function
B) non-inline member function
C) static member function
D) dynamic member function
12. A …………. can have access to only other static members declared in the same class.
A) constant member function
B) private member function
C) static member function
D) friend function
13. A static member function can be called using the ………………… instead of its objects.
A) variable name
B) function name
C) Class name
D) object name
14. Data members and member functions of a class in C++ program are by default
A. protected
B. public
C. private
D. None
A. :
B. ::
C. #
D. None
A. Car obj;
B. Car *obj = new Car();
C. Only B
D. A & B both
A. Class
B. Int
C. Float
D. Array
20. When you create an object of a class A like A obj ; then which one will be called automatically
A. Constructor
B. Destructor
C. Copy constructor
D. Assignment operator
A. Derived class constructor is called first then the base class constructor
B. Base class constructor is called first then derived class constructor
C. base class constructor will not be called
D. none of the above
22. The class in C++ which act only as a base class and object of it cannot be created is
A. parent class
B. super class
C. abstract class
D. none of the above
23. We can define a new class from an existing class, which of the following is used.
A. Composition
B. Inheritance
C. Constructors
D. Both A and B
24. Data encapsulation and data hiding are key features of. select the correct option.
A. object-oriented language
B. procedural language
C. machine language
D. structural language
25. When a data member of the new class is an object of another class is called ___________.
96) In C++, the statements are enclosed within 103) 31. In C++, ………. is the statement
a) parenthesis terminator
b) square brackets a) semicolon
c) curly brackets b) colon
d) None of the above c) new line
Answer: C d) None of the above
Answer: A
97) The following tells the compiler where the
program begins 104) Modules operator (%) has higher
a) Function prototype precedence than
b) Forward declaration of class a) Divide (/) operator
c) main() b) Multiply (*) operator
d) None of the above c) Negation (unary minus)
Answer: C d) Bitwise left shift operator
Answer: C
105) The result of the following statement is 110) Data members and member functions are
int y = 7; enclosed within
int ans = ++y; a) class
cout<<”ans=”<<ans; b) structure
cout<<”y”<<y; c) union
a) ans=7, y=7 d) None of the above
b) ans=8,y=7 Answer: A
c) ans=8,y=8;
d) none of the above 111) Inline functions are
Answer: C a) Declared in the class defined outside the
class
106) Consider the following if construct b) Defined outside the class using keyword
If(x=0) intime
cout<<”Inside loop!”; c) Defined inside the class using keyword inline
cout<<”Outside loop”; d) None of the above
The result of the above code segment is. Answer: B
a) inside loop
b) outside loop 112) The default class access scope is
c) both (a) & (b) a) Private
d) none of the above b) Public
Answer: B c) Protected
d) None of the above
107) The result of 2 & 3 is Answer: A
a) 2
b) 3 113) The default scope for a structure is
c) 5 a) Private
d) none of the above b) Public
Answer: A c) Protected
d) None of the above
108) Which of the following statements Answer: B
regarding enumerators is false?
a) Enumeration is an alternative method for 114) The private data members of a class are
naming integer constants/ accessible
b) An enumerator value can’t be changed in a a) Directly to objects of that class
program b) Only to the member functions
c) An integer value may be assigned to an c) To any function defined outside a class
enumerated variable d) None of the above
d) An enum defined within a structure is local Answer: B
to the structure
Answer: C 115) The objects can directly access
a) Public members
109) Which of the following statements is b) Private members
false? c) Both (a) & (b)
a) typedef defines new data types d) None of the above
b) Using typedef does not replace the standard Answer: A
C++ data type name with the new name
c) The new name defined by typedef, can be 116) The following is a valid statement in C++
used as a type for another typedef a) int x=(int)2.50;
d) None of the above b) int x=int(2.50);
Answer: A c) Both (a) & (b)
d) None of the above
Answer: C
117) Which of the following operator can be 123) When a member function of a class call
overloaded another member function, it is
a) Member access operator ( . & .*) a) Nesting of classes
b) Conditional operator (?:) b) Nesting of functions
c) Scope resolution operator (::) c) Nesting of objects
d) None of the above d) None of the above
Answer: D Answer: B
118) Using same function name to perform 124) A function defined inside a class is called
different tasks is a) A class function
a) Function polymorphism b) A friend function
b) Runtime polymorphism c) A member function
c) Function prototype d) None of the above
d) None of the above Answer: C
Answer: A
125) Information is made shareable through
119) Default argument is a) inheritance
a) Specified in function definition b) data encapsulation
b) Specified in function declaration c) data abstraction
c) Specified from left to right d) none of the above
d) None of the above Answer: A
Answer: B
126) Functions can returns
120) What is wrong with the following a) arrays
statement? b) reference
float s_interest (float principal, int rate=0.25, c) object
int time); d) all of the above
a) variables must not be specified in function Answer: D
prototype
b) arguments may only be defaulted from right 127) The memory for date members is
to left allocated
c) the default value must be specified when a) When a class is defined
making a function call b) When an object is initialized
d) none of the above c) When an object is created
Answer: B d) None of the above
Answer: B
121) Which of the following statements
regarding function overloading is not true. 128)The memory for member functions is
a) If is used to handle different data types at allocated
one place a) When a class is defined
b) When making a function call, if no exact b) When a object is created
match is found, promotion is the only criteria c) When an object is initialized
to find a match. d) None of the above
c) The default arguments can not be used Answer: A
instead of overloading
d) Unrelated functions should not be 129) The dot operator relates
overloaded a) A class member and a class object
Answer: C b) A class object and a class
122) The private members of a class c) A class and a member of that class
implement the OOP concept of d) A class object and member of that class
a) Data abstraction Answer: D
b) Data hiding
c) Message passing
d) None of the above
Answer: B
130) A class having another class definition is 137) new operator is used
a) Nested class a) to define a new variable
b) Subordinate class b) to create a new data type
c) Enclosing class c) to allocate memory dynamically
d) None of the above d) none of the above
Answer: C Answer: C
131) A class whose member functions are 138) A constructor function is generally
friends of other class is defined
a) Friend class a) In the public section of a class
b) Abstract class b) In the private section of a class
c) Virtual class c) In the protected section of a class
d) None of the above d) None of the above
Answer: A Answer: A
132) The data members of a class are 139) A class having no public constructors is
initialized a) A private class
a) in class definition b) A public class
b) by a non-member function c) An abstract class
c) through constructor function when a class d) None of the above
object is created Answer: A
d) none of the above
Answer: C 140) If a constructor function is defined in
private section of a class, then
133) A constructor function is a) The object cannot be created
a) A friend function to a class b) Only member functions and friends may
b) A member function with the same name as declare objects of the class
its class c) Both (a) & (b)
c) A non-member function d) None of the above
d) None of the above Answer: C
Answer: B
141) A constructor with no argument is
134) An enumerated type is composed of a) Default constructor
a) Integer values with user defined name b) Parameterized constructor
b) Variables of different data types c) Copy constructor
c) Constant numeric values d) None of the above
d) None of the above Answer: A
Answer: A
142) If default arguments are provided to a
135) In C++, the arguments by default are constructor function, then it becomes
passed by a) Default constructor
a) call be reference b) Copy instructor
b) call be value c) Parameterized constructor
c) both (a) & (b) d) None of the above
d) none of the above Answer: A
Answer: B
143) The class of which the objects are not
136) is an example of instantiated is
a) unary operator a) Abstract class
b) binary operator b) Virtual class
c) ternary operator c) Static class
d) none of the above d) None of the above
Answer: C Answer: A
144) && denotes 151) Which of the following statements
a) logical OR regarding constructor is false?
b) logical AND a) A constructor may be defined static
c) Bitwise AND b) Constructor can have default arguments
d) None of the above c) Member functions may be invoked from
Answer: B within a constructor
d) None of the above
145) The parameterized constructor Answer: A
a) Needs initial values as arguments during
creation of an object 152) The antonym of constructor is
b) Can be invoked explicitly only a) Creator
c) Can be invoked implicitly only b) Destructor
d) None of the above c) Destroyer
Answer: A d) None of the above
Answer: B
146) Explicit call to a constructor means
a) Providing the constructor name explicitly to 153) Variable …………. of void type
invoke it a) May be declared
b) Not providing the construction name at all b) Cannot be declared
c) Is the shorthand method c) Can be initialized
d) None of the above d) None of the above
Answer: A Answer: B
Features of OOP -
Class (blueprint )
Object ( instance of class or variable of class)
Encapsulation( binding data and functions together as one unit)
Abstraction(Data abstraction refers to providing only essential information to the outside world
and hiding their background details)
Polymorphism ( Ability to take more than one form)
Inheritance( Code reusability)
Dynamic Binding( determining method to invoke at run time )
32 keywords in c++
Using namespace std;
Here, std is the namespace where ANSI C++ standard class libraries are defined.
cin and cout belongs to std namespace
In C++, stream insertion operator << is used for output ie cout<< data;
In C++, stream extraction operator >> is used for input ie cin>>data;
Inline functions: Inline function is a function that is expanded in line when it is called. When the
inline function is called whole code of the inline function gets inserted or substituted at the point
of inline function call.
̳this„ pointer:
THIS pointer refers to the current object of a class. THIS keyword is used as a pointer which
differentiates between the current object with the global object. Basically, it refers to the current
object.
In call by value method, the value of the actual parameters is copied into the formal parameters.
The call by reference method of passing arguments to a function copies the address of an
argument into the formal parameter
Function Overloading:
Function overloading is a feature in C++ where two or more functions can have the same name
but different parameters. In Function Overloading ―Function‖ name should be the same and the
arguments should be different. Function overloading is defined as a normal function, but it has
the ability to perform different tasks. It allows creation of several methods with the same name
which differ from each other by type of input and output of the function.
Example:
void add(int& a, int& b);
void add(double& a, double& b);
void add(struct bob& a, struct bob& b);
Operator overloading is a function where different operators are applied and depends on the
arguments. Operator,-,* can be used to pass through the function, and it has their own
precedence to execute. Overloaded operators are functions with special names: the keyword
"operator" followed by the symbol for the operator being defined. Like any other function, an
overloaded operator has a return type and a parameter list.
Example: Unary operator overloading like ++ or – operator
new and delete are memory management operators in C++. new operator is used to create new
memory and delete to delete memory allocated
MCQ
The wrapping up of data and functions into a single unit (called class) is known as__________
a. polymorphism
b. inheritance
c. encapsulation
d. None of above
Answer: c
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: C
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: B
______________means we can use the same function name to create functions that perform a
variety of different tasks.
a. Polynomials
b. Function overloading
c. Namespace
d. None of above
Answer: b
Name the function whose definition can be substituted at a place where its function call is made
_________
a) friends function
b) inline function
c) volatile function
d) external function
Answer: b
Which among the following is true?
Answer: c
The operator <<
is called
A. Insertion operator
B. Extraction operator
C. Object
D. Function
ANSWER: A
A function argument is
A) a variable in the function that receives a value from the calling program.
B) a way that functions resist accepting the calling program‟s values.
C) a value sent to the function by the calling program.
D) a value returned by the function to the calling program.
Ans: C
>> operator is called
A. Insertion operator
B. Extraction operator
C. Object
D. Function
ANSWER: B
Everything defined at the program scope level (ie. outside functions and classes) is said to be
_______
A) local scope
B) regional scope
C) global scope
D) static scope
Answer: C
If function does not return any value then its return type is
A. Int
B. Float
C. Void
D. Char
ANSWER: C
Which method of parameter passing does not change the original variable
A. Call by value
B. Call by reference
C. Call by pointers
D. Both b and c
ANSWER: A
What is encapsulation?
A. It is collection of similar data items
B. It is combination of similar data items and the function
C. It is the combination of data items and function
D. It is the division of program into independent module
ANSWER: B
A variable is defined within a block in a body of a function. Which of the following are true?
A) It is visible throughout the function.
B) It is visible from the point of definition to the end of the program.
C) It is visible from the point of definition to the end of the block.
D) It is visible throughout the block.
Answer : D.
When the code to be linked with the call is known at compile time that situation is called as
a. Binding
b. late binding
c. static binding
d. dynamic binding
Answer:c
The signature of function is
a) The number & type of arguments
b) The return type of a function
c) The class definition
d) None of the above
Answer: a
Which of the following ways are legal to access a class data member using this pointer?
a) this.x
b) *this.x
c) *(this.x)
d) (*this).x
Answer:d
this pointer
a) implicitly points to an object.
b) can be explicitly used in a class.
c) can be used to return an object.
d) All of the above.
Answer:d
What are arrays in the C++?
A. A series of elements of same type placed in continuous block of memory.
B. A series of elements of different type placed in continuous block of memory.
C. A series of elements of same type placed in non-continuous block of memory.
D. A series of elements of different type placed in non-continuous block of memory.
Answer: A
Which of the following operator is used to release the dynamically allocated memory in C++?
a. remove
b. free
c. delete
d. both b and c
Answer: c
If an array is declared as
int a[5] = {3, 0, 1, 2}, then values assigned to a[0] & a[4] will be ________
#include<iostream>
using namespace std;
int main()
{ int a[5] ={3,0,1,2};
cout<<a[0];
cout<<a[4];
return 0;
}
A) 32
B) 02
C) 30
D) 04
Ans: C) 30
If the variable count exceeds 100, a single statement that prints “Too many” is
(A) if (count<100) cout<< “Too many”;
(B) if (count>100) cout>> “Too many”;
(C) if (count>100) cout<< “Too many”;
(D) None of these.
Ans: C
cout<< total;
cout<< sum;
Ans: C
Answer: A
a. 22
b.37
c.7
d. Error. Cannot be executed
Answer: B
a. 1
b. 0
c. 10
d. error
Answer: a
What will be the output of following program?
#include<iostream>
using namespace std;
int main()
{
float x;
x=(float)9/2;
cout<<x;
return 0;
}
a. 4.5
b. 4.0
c. 4
d. 5
Answer: a
OOP MCQ Unit-II
A class is a user defined data type which binds data and its associated functions together. Data
and member functions can be labeled by access specifiers as private, protected and public.
Example: Student
class Student
{
int age; //data is age and by default it is labeled by access specifier private
public:
void display() //display function labeled as public
{
}
return 0; //needed
}; //semicolon is needed to represent end of class
class Student
int age;
void display()
object stud
int age;
Whenever object gets created it gets only memory for data allocation while Function memory is
comman for all objects
Static data member: Only one copy of that member is created for the entire class and is
shared by all the objects of that class, no matter how many objects are created.
Constructor is a method used to initialize the state of an object, and it gets invoked at the time of
object creation. Rules for constructor are: Constructor Name should be same as class name.
Constructor must have no return type.
Destructor is a method which is automatically called when the object is made of scope or
destroyed. Destructor name is also same as class name but with the tilde symbol before the name.
Default Constructor: If programmer provides a constructor for the class without parameter
explicitly that is called default constructor.
Parameterized Constructor: If programmer provides a constructor for the class without parameter
explicitly that is called default Parameter less constructor.
Copy Constructor: A copy constructor is a member function that initializes an object using
another object of the same class. A copy constructor has the following general function
prototype: ClassName (const ClassName &old_obj);
MCQ :
Answer : C
Answer: B
When you create an object of a class A like A obj ; then which one will be called automatically
A. Constructor
B. Destructor
C. Copy constructor
D. Assignment operator
Answer: A
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: D
Constructor is a_______
A. class automatically called whenever a new object of this class is created
B. A class automatically called whenever a new object of this class is destroyed
C. A function automatically called whenever a new object of this class is created
D. A function automatically called whenever a new object of this class is destroyed
Answer: Option C
Which of the following is correct in C++?
a) Classes cannot have protected data members
b) Structures can have member functions
c) Class members are public by default
d) Structure members are private by default
Answer: b
Answer: A
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.
Ans b
Which value will it take when both user and default values are given?
a) user value
b) default value
c) custom value
d) defined value
Answer: a
If we start our function call with default arguments means, what will be proceeding arguments?
a) user argument
b) empty arguments
c) default arguments
d) user & empty arguments
Answer: c
Which operator a pointer object of a class uses to access its data members and member
functions?
a) .
b) ->
c) :
d) ::
Answer: a
The constructors and destructors for objects are automatically invoked ____.
A. by making explicit call to constructor and destructor functions
B. when object enters and leaves its scope.
C. when inheritance occurs
D. none of these
Answer: B
Which of the following keywords are used to control access to a class member?
a) default
b) break
c) protected
d) goto
Answer: c
Which of the following parameter passing mechanism is/are supported by C++ but not in C?
[A] Pass by value
[B] Pass by reference
[C] Pass by value result
[D] All of the above
Answer: B
Given a class named Book, which of the following is not a valid constructor?
(A) Book ( ) { }
(B) Book ( Book b) { }
(C) Book ( Book&b) { }
(D) Book (char* author, char* title) { }
Answer: B
The destructor has the same name as the constructor, but is preceded by a
A - '~'
B - '-'
C - '^'
D - '::'
Answer: A
Which of the following correctly declares an array of objects for a class ABC?
a) ABC array[10];
b) ABC array;
c) array{10};
d) array array[10];
Answer: A
a) data members
b) member functions
c) both data members and member function
d) None of these
Answer: B
m = n;
n = x;
}
main() {
int x = 5, y = 3;
swap(x,y);
cout<<x<<" "<<y;
return 0;
}
A-35
B-53
C-55
D - Compile error
Answer: B
classabc
{
private:
int array1[5]={0,2,4,8,5};
public:
void compute();
};
voidabc ::compute()
{
int result=0;
for(inti=0;i<5;i++)
{
result=result+array1[i];
}
cout<< result;
}
int main()
{
abc x;
x.compute();
return 0;
}
a) 19
b) 20
c) Garbage value
d) Syntax error
Answer: a
Polymorphism, a Greek term, means the ability to take more than one form. An operation may
exhibit different behavior is different instances. The behavior depends upon the types of data
used in the operation.
For example, consider the operation of addition. For two numbers, the operation will
generate a sum. If the operands are strings, then the operation would produce a third
string by concatenation. The process of making an operator to exhibit different behaviors
in different instances is known as operator overloading.
Overloaded operators are functions with special names: the keyword "operator" followed by the
symbol for the operator being defined. Like any other function, an overloaded operator has a
return type and a parameter list.
declares the addition operator that can be used to add two Box objects and returns final Box
object. Most overloaded operators may be defined as ordinary non-member functions or as class
member functions. In case we define above function as non-member function of a class then we
would have to pass two arguments for each operand as follows −
Box operator+(const Box&, const Box&);
Rules for Overloading Operators:
1. Only built-in operators can be overloaded. New operators can not be created.
2. Arity of the operators cannot be changed.
3. Precedence and associativity of the operators cannot be changed.
4. Overloaded operators cannot have default arguments except the function call operator ()
which can have default arguments.
5 .The overloaded operator must have at least one operand is of user defined type.
6.We cannot change the basic meaning of an operator. That is to say, we cannot redefine the
plus (+) operator to subtract one value from the other.
7.We cannot use friend functions to overload certain operators. The list is given below:
Assignment Operator =
Function call Operator ( )
Subscription Operator [ ]
Class member access operator ->
Except the operators specified, all other operators can be either member functions or a non
member functions.
8.Some operators like (assignment)=, (address)& and comma (,) are by default overloaded.
9.Unary operators, overloaded by means of a member function, take no explicit arguments and
return no explicit values, but, those overloaded by means of a friend function, take one
reference argument (the object of the relevant class).
10.Binary operator overloaded through a member function take one explicit argument and those
which are overloaded through a friend function take two explicit argument.
11.When using binary operators overloaded through a member function, the left hand operand
must be an object of relevant class.
12. Binary arithmetic operators such as +, -, * and / must explicitly return a value. They must not
attempt to change their own arguments
MCQ
Answer: d
Explanation: Operator overloading helps programmer to give his/her own meaning to an operator
for user defined data types (eg, classes).
Which is the correct statement about operator overloading in C++?.
A. Only arithmetic operators can be overloaded
B. Associativity and precedence of operators does not change
C. Precedence of operators are changed after overlaoding
D. Only non-arithmetic operators can be overloaded
Ans : B
Explanation: Both arithmetic and non-arithmetic operators can be overloaded. Priority and
affiliation of operators remain before and after operator overloading.
What is the syntax of overloading operator + which return int data type ?
a) int operator+(arguments){}
b) operator[+](argument_list){}
c) int +(argument_list){}
d) int [+](argument_list){}
Answer: a
Explanation: The general syntax for operator overloading is:
return_type operator OperatorSymbol(argument_list){}
Answer: E
Answer: b
Explanation: As the word binary itself means 2 therefore a binary operator operates on two
operands.
Which is the correct example of a binary operator?
a) ++
b) —
c) Dereferencing operator(*)
d) +
Answer: d
Explanation: +(adding two operands) requires two operands whereas ++(increases value by 1), –
(decreases value by 1) and *(dereferencing operator used for accessing value of pointers)
requires only one operand.
Answer: c
Explanation: &, == and / requires two operands whereas — requires only one operand, in
general, it decreases the value of operand by 1.
Answer: b
Explanation: Arity means a number of operands an operator requires to perform its action and
operator overloading does not changes the arity of any operator.
Answer: d
Using friend operator function, following perfect set of operators may not be overloaded.
a. = , ( ) , [ ] , ->
b. <<, = = , [ ] , >>
c. ?, = , ( ) , ++
d. None of these
Answer: a
we can define a binary operator as :
A. The operator that performs its action on two operand
B. The operator that performs its action on three operand
C. The operator that performs its action on any number of operands
Answer: A
Answer : C
Answer: C
In case of binary operator overloading with member function, which of following statement
should be taken into consideration?
a. Right hand operand must be object.
b. Left hand operand must be object.
c. Both the operands must be objects.
d. All of these should be considered.
Answer: b
While overloading unary operators using member function, it requires ___ argument?
A. 2
B. 1
C. 0
D. 3
Ans : C
While overloading binary operators using member function, it requires ___ argument?
A. 2
B. 1
C. 0
D. 3
Ans : B
While overloading unary operators using friend function, it requires ___ argument?
A. 2
B. 1
C. 0
D. 3
Ans : B
While overloading binary operators using friend function, it requires ___ argument?
A. 2
B. 1
C. 0
D. 3
Ans : A
A friend class can access ____________________ members of other class in which it is declared
as friend.
A. private
B. protected
C. public
D. Both A and B
Ans : D
Explanation: A friend class can access private and protected members of other class in which it is
declared as friend.
Ans : C
A. TRUE
B. FALSE
C. Can be true and false
D. Can not say
Ans : A
Explanation: Friendship is not mutual. If class A is a friend of B, then B doesn’t become a friend
of A automatically.
A. Friend functions use the dot operator to access members of a class using class objects
B. Friend functions can be private or public
C. Friend cannot access the members of the class directly
D. All of the above
Ans : D
Explanation: Friend function can be declared either in private or public part of the class. A friend
function cannot access the members of the class directly. They use the dot membership operator
with a member name.
Explanation: Friend functions are not in the scope of a class and hence cannot be called through
a class object. A friend function can access all types of members of the class. They can be
invoked as a normal function.
Which of the following operators should be preferred to overload as a global function rather than
a member method?
A. Postfix ++
B. Comparison Operator
C. Insertion Operator <<
D. prefix ++
Ans : C
Explanation: Insertion Operator should be preferred to overload as a global function rather than a
member method.
Which of the following operators should be preferred to overload as a global function rather
than a member method?
(A) Postfix ++
(B) Comparison Operator
(C) Insertion Operator <<
(D) Prefix++
Answer: (C)
Answer: C
Answer: B
Answer: c
Explanation: There are 3 different approaches used for operator overloading:
i. Overloading unary operator.
ii. Overloading binary operator.
iii. Overloading binary operator using a friend function.
Which of the following operator cannot be overloaded?
a) +
b) ?:
c) –
d) %
Answer: b
Explanation: ?: , :: and . cannot be overloaded +, -, % can be overloaded.
Answer: d
Explanation: ?:, :: and . cannot be overloaded whereas == can be overloaded.
Which of the following operator cannot be used to overload when that function is declared as
friend function?
a) -=
b) ||
c) ==
d) []
Answer: d
Explanation: When an operator overloaded function is declared as friend function then [] cannot
be overloaded.
Which of the following operator can be used to overload when that function is declared as friend
function?
a) []
b) ()
c) ->
d) |=
Answer: d
Explanation: When an operator overloaded function is declared as friend function then [], () and -
> cannot be overloaded.
OOP MCQs on Unit 4
Inheritance use is code reusability
Types: single, multiple ,multilevel, hierarchical , hybrid
Types of access specifiers : private, protected and public
scope of private variable : within base class only
protected variable : within base class and derived class,
public variable : through out program
static variable variable means comman memory of variable for all object
virtual keyword use to remove ambiguity in multiple inheritance
In above image, for Single Inheritance A is base class and B is derived class
For Multiple inheritance, A and B are base class and C is derived class
For multilevel inheritance, A is base class for derived class B and B is base class for
derived classC
For Hierarchical Inheritance, B, C and D are derived classes from Base class A
For Hybrid Inheritance, B and C are derived classes from Base class A and D is derived
class from Base class B and C ( So here hybrid inheritance is combination of Hierarchical
inheritance and Multiple inheritance )
TYPES OF INHERITANCE
1. In public inheritance of base class for derived class, all public members of base class
inherited as public in derived class, protected members of base class inherited as protected in
derived class and private members of base class inherited as private members in derived class
2. In protected inheritance of base class for derived class, all public members of base class
inherited as protected members in derived class , protected members of base class inherited as
protected members in derived class and private members of base class inherited as private
members in derived class
3. In private inheritance of base class for derived class, all public members of base class
inherited as private members in derived class, protected members of base class are inherited as
private members in derived class and private members of base class inherited as private members
in derived class
Single Inheritance
class Child : public Parent
class B : public A
(here B is derived class and A is base class)
Multiple Inheritance
class Child : public Parent1, public Parent2
class C : public A, public B
(here C is derived class and A and B are base class)
MCQ
a) Inheritance
b) Overloading
c) Polymorphism
d) None of the above
The derivation of Child class from Base class is indicated by ____ symbol.
A. ::
B. : (colon operator)
C. ;
D. |
When a derived class inherits only from one class and is not further inherited is
a) single inheritance
b) multiple inheritance
c) multilevel inheritance
d) hybrid inheritance
Class C is derived from class B and class B is derived from class A then it is called ____.
A. Single inheritance
B. Multiple inheritance
C. Multilevel inheritance
D. Hybrid inheritance
Class D is derived from class Base1 and class Base2 then it is called ____.
A. Single inheritance
B. Multiple inheritance
C. Multilevel inheritance
D. Hybrid inheritance
Class B and C are derived from class A and class D is derived from class B and C, then it is
called _____.
A. Single inheritance
B. Multiple inheritance
C. Multilevel inheritance
D. Hybrid inheritance
If a class C is derived from class B, which is derived from class A, all through public
inheritance, then a class C member function can access
(A) protected and public data only in C and B.
(B) protected and public data only in C.
(C) private data in A and B.
(D) protected data in A and B.
a. 20
b. 10
c. 11
d. None of above
Answer: b
Following keyword is used before a function in a base class to be overridden in derived class in
C++
a) override
b) virtual
c) void
d) none
In case of inheritance where both base and derived class are having constructors, when an object
of derived class is created then___________
A. constructor of derived class will be invoked first
B. constructor of base class will be invoked first
C. constructor of derived class will be executed first followed by base class
D. constructor of base class will be executed first followed by derived class
Run time polymorphism is achieved only when a ……………….. Is accessed through a pointer
to the base class.
A) static function
B) Real function
C. Member function
D) Virtual function
In case of inheritance where both base and derived class are having constructor and destructor,
then which if the following are true ?
1. Constructors are executed in their order of derivation
2. Constructors are executed in reverse order of derivation
3. Destructors are executed in their order of derivation
4. Destructors are executed in reverse order of derivation
a. Only 2 ,4
b. Only 1 , 3
c. Only 1 , 4
d. Only 2, 3
What will be the order of execution of base class constructors in the following method of
inheritance class a: public b, public c {...};
A. b(); c(); a();
B. c(); b(); a();
C. a(); b(); c();
D. b(); a(); c();
Explain : here b and c are base class so their constructors will be executed first
Which of the following advantages we lose by using multiple inheritance?
A. Dynamic binding
B. Polymorphism
C. Both Dynamic binding & Polymorphism
D. None of the mentioned
Containers are having same types, that’s why they are called
a. Heterogeneous
b. Homogeneous
c. Vectors
d. None of them
Answer: b
Any changes made to static data member from one member function _____________
a) Is reflected to only the corresponding object
b) Is reflected to all the variables in a program
c) Is reflected to all the objects of that class
d) Is constant to that function only
Answer: c
Explanation: The changes made from any function to static data member will be a common
change for all the other objects also. If the change is made with respect to one object and change
is printed from another object, the result will be same.
Which among the following is correct definition for static member functions?
a) Functions created to allocate constant values to each object
b) Functions made to maintain single copy of member functions for all objects
c) Functions created to define the static members
d) Functions made to manipulate static programs
Answer: b
Explanation: The functions which are made common, with respect to definition and data usage,
to all the objects. These functions are able to access the static data members of a class.
If the base class is derived using protected mode then public members of the base class become
___ of derived class.
A. public members
B. private members
C. protected
D. none of these
If the base class is derived using protected mode then protected members of the base class
become ___ of derived class.
A. public members
B. private members
C. protected
D. none of these
15. The process of building new classes from existing one is called
(A) Structure.
(B) Inheritance.
(C) Polymorphism.
(D) Template.
What is the difference between protected and private access specifiers in inheritance?
A. private member is not inheritable and not accessible in derived class.
B. protected member is inheritable and also accessible in derived class.
C. Both are inheritable but private is accessible in the derived class.
D. Both are inheritable but protected is not accessible in the derived class.
During a class inheritance in C++, if the visibility mode or mode of derivation is not provided,
then by default visibility mode is ___________.
A. public
B. protected
C. private
D. Friend
(B) A “static” member of a class can be initialized only within the class it is a member of.
(C) A “static” member of a class can be initialized before an object of that class is created.
(D) Since a “static” member of a class is actually a global element, it does not
require a class/object qualifier to access it independently of class/object.
Assume that we have constructor functions for both base class and derived class. Now
consider the declaration in
main()
Base *P=New Derived;
In what sequence will the constructor be called?
Which of the following is/are correct with reference to Abstract class and interface?
a. A class can inherit only one Abstract class but may inherit several interfaces
b. An abstract class can provide complete and default code but an interface has no code
A. a is true
B. b is true
C. Both a and b are true
D. Neitehr a nor b are true
Which of the following is/are correct with reference to Abstract class and interface?
a. A class can inherit only one Abstract class but may inherit several interfaces
b. An abstract class can provide complete and default code but an interface has no code
A. a is true
B. b is true
C. Both a and b are true
D. Neither a nor b are true
Which of the following differentiates between overloaded functions and overridden functions
?
When a class serves as base class for many derived classes, the situation is called:
a) polymorphism
b) hierarchical inheritance
c) hybrid inheritance
d) multiple inheritance
Which problem may arise if we use abstract class functions for polymorphism?
a) All classes are converted as abstract class
b) Derived class must be of abstract type
c) All the derived classes must implement the undefined functions
d) Derived classes can’t redefine the function
When the inheritance is private, the private methods in base class are __________ in the derived
class (in C++).
A. Inaccessible
B. Accessible
C. Protected
D. Public
What will be the output of the following code?
#include <iostream>
using namespace std;
class A
{
private:
int x;
protected:
int y;
public:
int z;
};
class B:protected A
{
public:
void display()
{
x=10;
y=20;
z=30;
}
};
A. x=10,y=20,z=30
B. error for x,y=20,z=30
C. error for x and y,z=30
D. error for x,y and z
Explanation: here x , y are declared private so they are not accessible outside class A
class A
{
public:
A()
{
cout<<"base class constructor";
}
};
class B:public A
{
public:
B()
{
cout<<"Derived Class Constructor";
}
};
int main()
{
B b;
return 0;
}
A. base class constructor
B. base class constructor derived class constructor
C. base class constructorDerived class constructor
D. derived class constructor base class constructor
If 2 classes derive one base class and redefine a function of base class, also overload some
operators inside the class body. Among these two things of function and operator overloading,
where is polymorphism used?
a) Function overloading only
b) Operator overloading only
c) Both of these are using polymorphism
d) Either function overloading or operator overloading because polymorphism can be
applied only once in a program
Example:
template<typename T>
T max(T a, T b)
{ return a > b ? a : b; }
class className
{
... .. ...
public:
T var;
T someOperation(T arg);
... .. ...
};
Namespace:
A namespace is a declarative region that provides a scope to the identifiers (names of the
types, function, variables etc) inside it.
A namespace definition begins with the keyword namespace followed by the namespace name
as follows –
namespace namespace_name {
// code declarations
}
To call the namespace-enabled version of either function or variable, prepend (::) the
namespace name as follows –
name::code; // code could be variable or function.
try
catch
throw
try – throw-catch
try block (contain set of statements where exception can occur)
throw − A program throws an exception when a problem shows up.
catch block: A program catches an exception with an exception handler at the place in a
program where you want to handle the problem. The catch keyword indicates the catching of an
exception.
Syntax
try
{
//code
throw parameter;
}
catch(exceptionname ex)
{
//code to handle exception
}
Stream classes in C++ to take input from keyboard and display output on screen
istream
ostream
The cin object in C++ is an object of class istream
The cout object in C++ is an object of class ostream
iostream is derived class from istream and ostream (thus it can use both cin and cout)
MCQ
What is a template?
a. Inheritance
b. Virtual Functions
c. templates
d. None of these
The code of statements which may cause abnormal termination of the program shown written
under_________ block.
a. try
b. catch
c. finally
d. None of these
a. Only 1, 4, 5
b. Only 1, 2, 3
c. Only 1, 4
d. Only 1, 2
In nested try block, if inner catch handler gets executed, then __________?
A. Program execution stops immediately.
B. Outer catch handler will also get executed.
C. Compiler will jump to the outer catch handler and then executes remaining executable
statements of main().
D. Compiler will execute remaining executable statements of outer try block and then
the main().
A. Producing functions
B. Producing classes
C. Nothing
D. Both A and B
A. 1
B. 2
C. 3
D. 4
A. Only i, iv, v
B. Only i, ii, iii
C. Only i, iv
D. Only i, ii
Templates are abstract recipe for producing a concrete code, and it is used for
a. Producing functions
b. Producing classes
c. Nothing
d. Both A and B
What will happen when a programs throws any other type of exception other than
specified?
a) terminate
b)arise error
c)run
d)throw
a) conditional operator
b) ternary operator
c) scope operator
d) None of the mentioned
a) namespace::operator
b) namespace,operator
c) namespace#operator
d) namespace$operator
Answer: a
Explanation: An exception is defined as the problem in C++ program that arises during the
execution of the program for example divide by zero error.
namespace B
{
int i = 15;
}
}
a) cout<<A::i;
b) cout<<B::i;
c) cout<<A::B::i;
d) cout<<i;
What will be the output of the following C++ code?
#include <iostream>
#include <typeinfo>
using namespace std;
class Polymorphic {virtual void Member(){}};
int main ()
{
try
{
Polymorphic * pb = 0;
typeid(*pb);
}
catch (exception& e)
{
cerr << "exception caught: " << e.what() << endl;
}
return 0;
}
int main()
{
try
{
throw 'b';
}
catch (int param)
{
cout << "Int Exception";
}
catch (...)
{
cout << "Default Exception";
}
cout << "After Exception";
return 0;
}
a) Default Exception After Exception
b) Int Exception After Exception
c) Int Exception
d) Default Exception
What may be the name of the parameter that the template should take?
a) same as template
b) same as class
c) same as function
d) same as member
Answer: a
Explanation: The name of the parameter that the template should take same as the template.
Which of the following best defines the syntax for template function ?
A. template return_type Function_Name(Parameters)
B. template return_type Function_Name(Parameters)
C. Both A and B
D. None of the above
FIle is structure and *ptr is pointer to file and tell_p() to get current position of file pointer in
file
eof() You can detect when the end of the file is reached by using the member function eof() which
has prototype : int eof(); It returns non-zero when the end of file has been reached, otherwise it
returns zero.
fseek() is used to move file pointer associated with a given file to a specific position
rewind() to set position to beginning and no way to check if the operations completed
successfully
ios::ate to open a file for output and move the read/write control to the end of the file
The ferror() function checks for any error in the stream. It returns a value zero if no error has
occurred and a non-zero value if there is an error. The error indication will last until the file is
closed unless it is cleared by the clearerr() function.
FILE READ/WRITE
Examples: lets say we want to read data from .txt file located on harddisk
So we can use command
ifstream fin ; //here we are creating fin as object of ifstream
// above read file using function open and by default open mode = ios::in mode
fin.open("sample.txt");
lets say we want to write data from .txt file located on harddisk
ofstream fout; //fout is object of stream class ofstream
// by default ios::out mode, automatically deletes
fout.open("sample.txt"); //write using open method
To close file
fin.close();
FILE MODES
Example :
Example of opening/creating a file using the open() function
#include<iostream>
#include <fstream>
using namespace std;
int main()
{
fstream new_file; //new_file is object of fstream
new_file.open("test.txt",ios::out); //open method to open file in out mode
if(!new_file)
{
cout<<"File creation failed";
}
else
{
cout<<"New file created";
new_file.close(); // Step 4: Closing file
}
return 0;
}
//In above example, file test.txt is open in with showing different modes of operation
Which of the following is used to create a stream that performs both input and output operations?
a) ofstream
b) ifstream
c) iostream
d) fstream
Answer:d
Explanation: fstream is used to create a stream that performs both input and output operations in C++
file handling.
Which function is used in C++ to get the current position of file pointer in a file?
a) tell_p()
b) get_pos()
c) get_p()
d) tell_pos()
Which member function is used to determine whether the stream object is currently associated with a
file?
A. is_open
B. Buf
C. String
D. None of the above
The __________ built in class can be used to create files and read information from them into
memory.
A. instream
B. ifstream
C. ofstream
D. istream
Which of the following is used to Open a file for output and move the read/write control to the end of
the file ?
A. ios::ate
B. ios::at
C. ios::ann
D. ios::end
A. Returns true if a file open for reading has reached the next character.
B. Returns true if a file open for reading has reached the next word.
C. Returns true if a file open for reading has reached the end.
D. Returns true if a file open for reading has reached the middle.
Answer: C
1) It is not possible to combine two or more file opening mode in open() method.
2) It is possible to combine two or more file opening mode in open() method.
3) ios::in and ios::out are input and output file opening mode respectively.
a) 1, 3
b) 2, 3
c) 3 only
d) 1, 2
Answer: a
Explanation: C++ allows to use one or more file opening mode in a single open() method. ios::in and
ios::out are input and output file opening mode respectively.
What is the use of ios::trunc mode?
a) To open a file in input mode
b) To open a file in output mode
c) To truncate an existing file to half
d) To truncate an existing file to zero
Answer: d
Explanation: In C++ file handling, ios::trunc mode is used to truncate an existing file to zero length.
Which of the following is the default mode of the opening using the ofstream class?
a) ios::in
b) ios::out
c) ios::app
d) ios::trunk
Answer: b
Explanation: By default, the file is opened in ios::out mode if the file object we are using is of
ofstream class.
A. ofstream
B. ifstream
C. fstream
D. iostream
Answer: a
A. >>
B. <<
C. <
D. None of the above
Answer: b
which mode opens the file and sends outputs at the end______
a. app
b. in
c. out
d. trunk
Which of the following is the default mode of the opening using the ifstream class?
a) ios::in
b) ios::out
c) ios::app
d) ios::trunk
Answer: a
Explanation: By default, the file is opened in ios::in mode if the file object we are using is of ifstream
class.
Answer: a
Explanation: ios::set is not used to seek file pointer. ios::end is used to seek from the end of the file.
ios::curr from the current position. ios::beg from the beginning.
The Shirpur Education Society’s
R. C. Patel Polytechnic, Shirpur [1808]
MCQ ON UNIT 3 INHERITANCE
Course Title: Object Oriented Programming using C++ Course Abbr.: OOP Course Code: 22316
Instructions:
1. Attempt minimum 30 out of 40 questions.
2. Each question carries 01 mark.
4. The ……………. inherits some or all of the properties of the ……….. class.
a base, derived b derived, base c derived, initial d base, final
5. A derived class with only one base class is called …………… inheritance.
a single b multiple c multilevel d hierarchical
6. A class can inherit properties from more than one class which is known as ……….inheritance.
a single b multiple
c multilevel d hierarchical
7. A class can be derived from another derived class which is known as ………. inheritance.
a single b multiple c multilevel d hierarchical
8. When a base class is privately inherited by a derived class public members of the base class
become ………. of the derived class.
a private members b protected c Public members d Not inherited
members
9. When a base class is privately inherited by derived class public members of the base class can
11. When a protected member is inherited in public mode, it becomes ……….. in the derived class too
and therefore is accessible by member functions of the derived class.
a protected b private c public d friend
12. State whether the following statements about inheritance are True or False.
i) A public member of a class can be accessed by its own objects using the dot operator.
ii) While inheriting, the private members of the base class will never become members of its derived
class.
a True, False b False, True c True, True d False, False
13. A member declared as ………….. is accessible by the member functions within its class and any
class immediately derived from it.
a protected b private c public d friend
14. State whether the following statements about inheritance are True or False.
i) A public member of a class can be accessed by its own objects using the dot operator.
ii) While inheriting, the private members of the base class will never become members of its derived
class.
a True, False b False, True c True, True d False, False
15. A member declared as ………….. is accessible by the member functions within its class and any
class immediately derived from it.
a protected b private c public d friend
16. When the base class is publicly inherited, public members of the base class become …………. of
the derived class.
a private members b protected c Public members d Not inherited
members
17. In the protected derivation, both the public and protected members of the base class become
…………. members of the derived class.
a protected b private c public d friend
18. What will be the order of execution of base class constructors in the following method of
inheritance?
class A: public B, public C {….};
a A) B(); C(); A(); b B) C(); B(); A(); c C) A(); B(); C(); d D) B(); A(); C();
19. What will be the order of execution of base class constructors in the following method of
inheritance?
class A: public B, virtual public C {….};
a B(); C(); A(); b C(); B(); A(); c A(); B(); C(); d B(); A(); C();
a Executed
b Error
c Runtime error
d None of the mentioned
22. In ……………………. inheritance, the constructors are executed in the order of inheritance.
a multipath b multiple c multilevel d hierarchical
23. The member functions of a derived class can directly access only the ……………….. data.
a private and protected b private and public
c protected and public d private, protected and public
24. The friend functions and the member functions of a friend class can directly access the
………………. data.
a private and protected b private and public
c protected and public d private, protected and public
25. When the inheritance is private, the private methods in base class are __________ in the derived
class (in C++).
a Inaccessible b Accessible
c Protected d Public
26. In ……………….. inheritance, the base classes are constructed in the order in which they appear in
the deceleration of the derived class.
a multipath b multiple c multilevel d hierarchical
27. ……………….. inheritance may lead to duplication of inherited members from a ‘grandparent’ base
class.
a multipath b multiple c multilevel d hierarchical
a In find
b In course
c Compiler Error: Ambiguous call to print()
d None of the above
33. ___________ inheritance may lead to duplication of inherited members from a "grandparent" base
class.
a Multipath b Multiple c Multilevel d Hierarchical
35.
class A
{
.........
};
class B : public A
{
..........
};
class C
{
...........
};
class D : public B, public C
{
...........
};
41. Which of the following is an invalid visibility label while inheriting a class
a public b private c protected d friend
40.
a b c d
41.
a b
40.
a b c d
41.
a b
40.
a b c d
41.
a b
https://www.siteforinfotech.com/2017/05/top-20-mcq-questions-inheritance-in-cpp.html
A. 2
B. 4
C. 2 or 4
ANSWER: A
A. array type
B. character type
C. boolean type
D. integer type
ANSWER: A
A. int
B. short
C. void
D. float
ANSWER: C
A. alert
B. backslash
C. tab
D. form feed
ANSWER: B
A. integer
B. boolean
C. character
ANSWER: B
A. enumeration
B. classes
C. both a and b
D. int
ANSWER: C
A. f is a function taking an argument of type int and retruning a floating point number
ANSWER: B
A. double
B. void
C. int
D. bool
ANSWER: A
9.When a language has the capability to produce new data type mean, it can be called as
A. overloaded
B. extensible
C. encapsulated
D. reprehensible
ANSWER: B
B. enumeration, classes
ANSWER: C
11.<< is called
A. Insertion operator
B. Extraction operator
C. Object
D. Function
ANSWER: A
12.>> is called
A. Insertion operator
B. Extraction operator
C. Object
D. Function
ANSWER: B
C. Iterative statement
D. Function
ANSWER: A
B. Test condition
ANSWER: A
ANSWER: A
ANSWER: B
A. cout
B. cin
C. header file
D. class
ANSWER: A
A. Function declaration
B. Function definition
C. Function call
D. Return type
ANSWER: A
C. Friend function
ANSWER: A
D. Anywhere
ANSWER: B
A. Actual parameter
B. Formal parameter
C. Global parameter
D. Auto parameter
ANSWER: A
A. Extern parameter
B. Formal parameter
C. Auto parameter
D. Register parameter
ANSWER: B
23.Which storage specifiers retains the value between the function call
A. Auto
B. Register
C. Extern
D. Static
ANSWER: D
24.If function does not return any value then its return type is
A. Int
B. Float
C. Void
D. Char
ANSWER: C
A. 1
B. 2
C. 0
D. 4
ANSWER: A
A. Function
B. File
C. Block
C. None
ANSWER: B
27.Which method of parameter passing does not change the original variable
A. Call by value
B. Call by reference
C. Call by pointers
D. Both b and c
ANSWER: A
B. Donald E. Knuth
D. Bjame Stroustrup
ANSWER: D
29.cfront
A. Pascal
B. Smalltalk
C. C
ANSWER: C
ANSWER: C
A. >>
B. ?:
C. .
ANSWER: D
A. class output
B. character output
C. common output
D. call output
ANSWER: C
A. start()
B. system()
C. main()
D. program()
ANSWER: C
36.What punctuation is used to signal the beginning and end of code blocks?
A. { }
D. ( and )
ANSWER: A
A. . (dot)
B. ; (semi-colon)
C. : (colon)
A. */ Comments */
B. ** Comment **
C. /* Comment */
D. { Comment }
ANSWER: C
A. float
B. real
C. int
D. double
ANSWER: B
A. :=
B. =
C. equal
D. ==
ANSWER: D
A. 1
B. 66
C. .1
A. &
B. &&
C. |
D. |&
ANSWER: B
43.The void specifier is used if a function does not have return type.
A. True
B. False
C. --
D. --
ANSWER: A
ANSWER: C
C. Both of these
D. None of these
ANSWER: A
46.There is a unique function in C++ program by where all C++ programs start their execution
A. Start()
B. Begin()
C. Main()
D. Output()
ANSWER: C
A. Parameters
B. Parenthesis
C. Curly braces
D. None of these
ANSWER: B
D. None of above
ANSWER: D
B. A Comma (,)
C. A Semicolon (;)
D. A colon (:)
ANSWER: C
ANSWER: D
ANSWER: B
ANSWER: B
53.What is encapsulation?
D. None of these
ANSWER: B
A. Letters
B. Digits
C. Underscores
D. Spaces
ANSWER: D
A. papername
B. writername
C. typename
D. printname
ANSWER: C
A. papername
B. writername
C. typename
D. printname
ANSWER: A
58.To increase the value of c by one which of the following statement is wrong?
A. c++;
B. c = c + 1;
C. c + 1 => c;
D. c += 1
ANSWER: C
D. All of these
ANSWER: A
60.What is the final value of x when the code int x; for(x=0; x<10; x++) {} is run?
A. 10
B. 9
C. 0
D. 1
ANSWER: A
Answer:d
Q2.which datatype is used to represent the absence of paramaters?
a) int
b) short
c) void
d) float
Answer:c
Answer:a
Q4.When a language has the capability to produce new data type mean, it can be called as
a) overloaded
b) extensible
c) encapsulated
d) reprehensible
Answer:b
Q5.In which type does the enumerators are stored by the compiler?
a) string
b) integer
c) float
d) none of the mentioned
Answer:b
Answer:d
Answer:a
Answer:a
Q9.Which allows you to create a derived class that inherits properties from more than one base class?
a. Multilevel inheritance
b. Multiple inheritance
c. Hybrid Inheritance
d. Hierarchical Inheritance
Answer:b
Answer:b
Q11. A function that changes the state of the cout object is called a(n) _____
a. member
b. adjuster
c. manipulator
d. operator
Answer:c
Q12. What does C++ append to the end of a string literal constant?
a. a space
b. a number sign (#)
c. an asterisk (*)
d. a null character
Answer:d
Answer:d
Q14. To hide a data member from the program, you must declare the data member in the _____ section of the class
a. concealed
b. confidential
c. restricted
d. private
Answer:d
Q15.The arguments that determine the state of the cout object are called
a. classes
b. manipulators
c. format flags or state flags
d. state controllers
Answer:c
Q16.Which of the following statements declares a variable that can contain a decimal number?
a. dec payRate;
b. dec hourlyPay
c. float payRate
d. float hourlyPay;
Answer:d
Answer:c
Answer:a
Answer:c
Answer:b
Answer:c
Q22. Which of the following type casts will convert an Integer variable named amount to a Double type?
a. (double) amount
b. (int to double) amount
c. int to double(amount)
d. int (amount) to double
Answer:a
Answer:d
Q24. You have assigned the address of Value to the pointer P, Which statement will display the value stored in
Value?
a. cout<<P;
b. cout<<*Value;
c. cout<<&P;
d. cout<<*<P;
Answer:d
Answer:b
Answer:a
Q27. Does this mentioning array name gives the base address in all the contexts?
a. Yes
b. No
Answer:b
Answer:b
Q29. Are the expressions arr and &arr same for an array of 10 integers?
a. Yes
b. No
Answer:b
Q30.The correct statement for a function that takes pointer to a float, a pointer to a pointer to a char and returns a
pointer to a pointer to a integer is
a) int **fun(float**, char**)
b) int *fun(float*, char*)
c) int ***fun(float*, char**)
d) int ***fun(*float, **char)
Answer:c
Answer:c
Answer:c
Answer:b
Q34. Which other keywords are also used to declare the class other than class?
a) struct
b) union
c) object
d) both a & b
Answer:d
Answer:a
Answer:b
Answer:a
Q38. When struct is used instead of the keyword class means, what will happen in the program?
a) access is public by default
b) access is private by default
c) access is protected by default
d) none of the mentioned
Answer:a
Answer:a
Answer:c
Q41. Which of these following members are not accessed by using direct member access operator?
a) public
b) private
c) protected
d) Both a & b
Answer:d
Answer:d
Answer:d
Q44. Which special character is used to mark the end of class?
a) ;
b) :
c) #
d) $
Answer: a
Answer: D
Answer: C
Answer:a
Answer:b
Answer:a
Answer:c
Answer:a
Answer:a
Answer:b
Answer:b
Answer:c
Answer:b
Answer:d
Answer: d
Answer: e
Answer: b
Answer: c
Answer: a
Answer: b
Answer:a
Answer: b
Answer:a
Answer: b
Answer:a
Answer:a
Q70. The entire set of data & code of an object can be made which data type using the concept of class
a. User-defined
b. static
c. global
d. derived
Answer:a
Answer:c
Q72. What provide the interface between the object’s data & the program
a. Data
b. class
c. methods
d.Encapsulation
Answer:c
Q73. The insulation of data from direct access by the program is called as
a. Encapsulation
b. Data hiding
c. Private
d. Data Abstraction
Answer:b
Q74. What is the process by which object of one class acquires the properties of object of another class.
a. Encapsulation
b. Data hiding
c. Inheritance
d.Polymorphism
Answer:c
Answer:b
Answer:b
Q77. The class from which the subclass derives the properties is called as
a. mainclass
b. subclass
c. baseclass
d. Superclass
Answer:d
Q78. The property or the ability to take more than one form is called as
a. Encapsulation
b. Polymorphism
c. Inheritance
d. Manyforms
Answer:b
Answer:c
Q80. The process of linking of a procedure call with the code to be executed is called as
a. Binding
b. Loading
c. Assembling
d. Debuging
Answer:a
Q81. What is the process in which the code to be linked with the procedure call is not know till execution time
?
a. Binding
b. early binding
c. static binding
d. dynamic binding
Answer:d
Q82. When the code to be linked with the call is known at compile time that situation is called as
a. Binding
b. late binding
c. static binding
d. dynamic binding
Answer:c
Answer: a
Answer: b
Q85. The binding of a function call at runtime is
a) Static binding
b) Early binding
c) Late binding
d) Runtime binding
Answer: c
Answer: d
Answer: b
Q88. Which constructor will initialize the base class data member?
a) derived class
b) base class
c) class
d) None of the mentioned
Answer:b
Q89. A remote control that is used to turn on or off some machine is also called a(n) _____.
a) class
b) interface
c) message
d) instance
Answer:b
Q90. In a student grading system, Student Last Name, Student Address, and Final Course Grade would all be
classified as what?
a)Inheritance
b)Information
c)Encapsulation
d)Polymorphism
Answer:b
Q91. What part of object-oriented technology defines superclass and subclass relationships?
a) Inheritance
b) Scalability
c) Encapsulation
d) Polymorphism
Answer:a
Q92. In a student grading system, objects from different classes communicate with each other. These
communications are known as _____.
a) inheritance
b) polymorphism
c) messages
d) concealment
Answer:c
Answer:d
Q94. What term is used to describe the internal representation of an object that is hidden from view outside the
object's definition?
a) Encapsulation
b) Expandable
c) Polymorphism
d) Inheritance
Answer:a
Q95. What programming language model is organized around "objects" rather than "actions"?
a) Java
b) OOB
c) Perl
d) C+
Answer:b
Q96. What are the instructions called that tell a system what, how, and when to do something?
a) Object-oriented technology approach
b) Object-oriented database
c) Program
d) Database management
Answer:c
Q97. What common technique attempts to save time and energy by reducing redundant work in object-oriented
programming?
a) Reduce lines of programming
b) Reuse of code
c) Reduce size of systems being developed
d) Merging different systems together
Answer:b
Answer:a
Answer:b
Answer: D
Answer:a
Answer:b
Answer:a
Answer:c
Q106. If a class C is derived from class B, which is derived from class A, all through public
inheritance, then a class C member function can access
a) protected and public data only in C and B.
b) protected and public data only in C.
c) private data in A and B.
d) protected data in A and B.
Answer:d
Answer:d
Answer:b
Q109. In C++, dynamic memory allocation is accomplished with the operator ____
a) new
b) this
c) malloc( )
d) delete
Answer:a
Answer: c
Answer:c
Answer:a
Answer:d
Answer:c
Answer:d
Answer:c
Answer:d
Answer:c
Q119.Given a class named Book, which of the following is not a valid constructor?
a) Book ( ) { }
b) Book ( Book b) { }
c) Book ( Book &b) { }
d) Book (char* author, char* title) { }
Answer:b
Q120.Which of the statements is true in a protected derivation of a derived class from a base class?
a) Private members of the base class become protected members of the derived class
b) Protected members of the base class become public members of the derived class
c) Public members of the base class become protected members of the derived class
d) Protected derivation does not affect private and protected members of the derived
class.
Answer:c
Answer:d
Answer:c
Answer:b
Q124.If there is a pointer p to object of a base class and it contains the address of an object of a
derived class and both classes contain a virtual member function abc(), then the statement
p->abc(); will cause the version of abc() in the __________class to be executed.
a) Base Class
b) Derived class
c) Produces compile time error
d) produces runtime error
Answer:b
Q125.We can output text to an object of class ostream using the insertion operator<< because
a) the ostream class is a stream
b) the insertion operator works with all classes.
c) we are actually outputting to cout.
d) the insertion operator is overloaded in ostream.
Answer:d
Answer:d
Q127.Name the header file to be included for the use of built in function isalnum()
a) string.h
b) process.h
c) ctype.h
d) dos.h
Answer:c
Answer:a
Answer:c
Answer:b
Answer:b
Answer:a
Q133.Which of the following ways are legal to access a class data member using this pointer?
a) this.x
b) *this.x
c) *(this.x)
d) (*this).x
Answer:d
Answer:c
Answer:d
Answer:d
Answer:d
Answer:a
Answer:c
Q140.Data members which are static
a) cannot be assigned a value
b) can only be used in static functions
c) cannot be defined in a Union
d) can be accessed outside the class
Answer:b
Q141.this pointer
a) implicitly points to an object.
b) can be explicitly used in a class.
c) can be used to return an object.
d) All of the above.
Answer:d
Answer:b
Answer:c
Answer: a
Answer: a
Answer: B
Q.146. Which of the following term is used for a function defined inside a class?
A. Member Variable
B. Member function
C. Class function
D. Classic function
Answer: B
Answer: D
Answer: C
Answer: B
Q.150 Which header file must be included for cin and cout?
(A) stdio.h
(B) conio.h
(C) iostream.h
(D) Both iostream.h and conio.h
Answer: C
Q.151 Which one of the following is correct about the statements given below?
A. Only II is correct.
B. Both I and II are correct.
C. Only I is correct.
D. Both I and II are incorrect.
Answer: C
Answer: B
A. none of these
B. their own header files
C. Auxiliary .cpp file
D. main .cpp files, along with function definitions
Answer: B
Answer: B
Answer: C
Answer: C
Answer: C
Answer:b
Answer:b
Answer: C
Q161.“H” is an example of
a) character literal
b) string literal
c) variable
d) None of the above
Answer: B
Answer: C
Answer: C
Answer: C
a) inside loop
b) outside loop
c) both (a) & (b)
d) none of the above
Answer: B
Answer: A
Answer: C
Answer: D
Answer: B
Answer: D
Answer:b
Answer:c
Answer:b
Answer:c
Q.176. When a language has the capability to produce new data type mean, it can be called as
a) overloaded
b) extensible
c) encapsulated
d) reprehensible
Answer:b
Answer:d
Answer:c
Answer:b
Q.182 For what values of the expression is an if-statement block not executed?
a) 0 and all negative values
b) 0 and -1
c) 0
d) 0, all negative values, all positive values except 1
Answer:c
Q.183 Which of the two operators ++ and — work for the bool datatype in C++?
a) None
b) ++
c) –
d) Both
Answer:b
#include <iostream>
using namespace std;
int f(int p, int q)
{
if (p > q)
return p;
else
return q;
}
main()
{
int a = 5, b = 10;
int k;
bool x = true;
bool y = f(a, b);
k =((a * b) + (x + y));
cout << k;
}
a) 55
b) 62
c) 52
d) none of the mentioned
Answer:c
#include <iostream>
using namespace std;
int main()
{
int p;
bool a = true;
bool b = false;
int x = 10;
int y = 5;
p = ((x + y) + (a + b));
cout << p;
return 0;
}
a) 0
b) 16
c) 12
d) 2
Answer:b
Answer:b
Answer:c
Answer:a
#include <stdio.h>
int main()
{
char a = '\012';
printf("%d", a);
return 0;
}
a) Compiler error
b) 12
c) 10
d) Empty
Answer:c
Q.191 In C++, what is the sign of character data type by default?
a) Signed
b) Unsigned
c) Implementation dependent
d) None of these
Answer:c
Answer:c
Answer:c
#include <iostream>
using namespace std;
int main()
{
int x = -1;
unsigned int y = 2;
if(x > y) {
cout << "x is greater";
} else {
cout << "y is greater";
}
}
a) x is greater
b) y is greater
c) Implementation defined
d) Arbitrary
Answer:a
Q.195 Which of these expressions will return true if the input integer v is a power of two?
a) (v | (v + 1)) == 0;
b) (v & (v – 1)) == 0;
c) (v | (v + 1)) == 0;
d) (v & (v – 1)) == 0;
Answer:d
Q.196 What is the value of the following 8-bit integer after all statements are executed?
int x = 1; 2 Marks
x = x << 7;
x = x >> 7;
a) 1
b) -1
c) 127
d) Implementation defined
View Answer
Answer:d
Q.197 What is the value of the following 8-bit integer after all statements are executed?
int x = 1;
x = x << 7; 2 Marks
x = x >> 7;
a) 1
b) -1
c) 127
d) Implementation defined
Answer:d
Q.198 Which of these expressions will make the rightmost set bit zero in an input integer x?
a) x = x | (x-1)
b) x = x & (x-1)
c) x = x | (x+1)
d) x = x & (x+1)
Answer:b
Q.199 Which of these expressions will isolate the rightmost set bit?
a) x = x & (~x)
b) x = x ^ (~x)
c) x = x & (-x)
d) x = x ^ (-x)
Answer:c
Q.200 Which of these expressions will isolate the rightmost set bit?
a) x = x & (~x)
b) x = x ^ (~x)
c) x = x & (-x)
d) x = x ^ (-x)
Answer:c
#include <iostream>
using namespace std;
int main()
{
int a = 8;
cout << "ANDing integer 'a' with 'true' :" << a && true;
return 0;
}
a) ANDing integer ‘a’ with ‘true’ :8
b) ANDing integer ‘a’ with ‘true’ :0
c) ANDing integer ‘a’ with ‘true’ :1
d) None of the mentioned
Answer:a
#include <iostream>
using namespace std;
int main()
{
int i = 3;
int l = i / -2;
int k = i % -2;
cout << l << k;
return 0;
}
a) compile time error
b) -1 1
c) 1 -1
d) implementation defined
Answer:b
int main()
{
register int i = 1;
int *ptr = &i;
cout << *ptr;
return 0;
}
a) 0
b) 1
c) Compiler error may be possible
d) Runtime error may be possible
Answer:c
Answer:b
Q.205 In which type does the enumerators are stored by the compiler?
a) string
b) integer
c) float
d) none of the mentioned
Answer:b
Answer:d
Answer:a
Answer:a
#include <iostream>
using namespace std;
enum cat {
temp = 7
};
int main()
{
int age = 14;
age /= temp;
cout << "If you were cat, you would be " << age << endl;
return 0;
}
a) If you were cat, you would be 5
b) If you were cat, you would be 2
c) If you were cat, you would be 7
d) none of the mentioned
Answer:b
Answer:a
#include <iostream>
using namespace std;
enum colour {
green, red, blue, white, yellow, pink
};
int main()
{
cout << green<< red<< blue<< white<< yellow<< pink;
return 0;
}
a) 0123456
b) 1111111
c) compile time error
d) runtime error
Answer:a
#include <iostream>
using namespace std;
int main()
{
enum channel {star, sony, zee};
enum symbol {hash, star};
int i = 0;
for (i = star; i <= zee; i++) {
printf("%d ", i);
}
return 0;
}
a) 012
b) 123
c) compile time error
d) runtime error
Answer:c
#include <iostream>
using namespace std;
int main()
{
int i;
enum month {
JAN = 1, FEB, MAR, APR, MAY, JUN, JUL, AUG, SEP, OCT, NOV, DEC
};
for (i = MAR; i <= NOV; i++)
cout << i;
return 0;
}
a) 01234567891011
b) 123456789101112
c) 34567891011
d) 123456789
Answer:c
Answer:C
Answer:c
Answer:b
Q.217 Which other keywords are also used to declare the class other than class?
a) struct
b) union
c) object
d) both a & b
Answer:d
#include <iostream>
using namespace std;
class rect
{
int x, y;
public:
void val (int, int);
int area ()
{
return (x * y);
}
};
void rect::val (int a, int b)
{
x = a;
y = b;
}
int main ()
{
rect rect;
rect.val (3, 4);
cout << "rect area: " << rect.area();
return 0;
}
a) rect area:12
b) rect area: 12
c) rect area:24
d) none of the mentioned
Answer:b
#include <iostream>
using namespace std;
class CDummy
{
public:
int isitme (CDummy& param);
};
int CDummy::isitme (CDummy& param)
{
if (¶m == this)
return true;
else
return false;
}
int main ()
{
CDummy a;
CDummy *b = &a;
if (b->isitme(a)) {
cout << "execute";
}
else
{
cout<<"not execute";
}
return 0;
}
a) execute
b) not execute
c) none of the mentioned
d) both a & b
Answer:a
Answer:a
Answer:b
Answer:a
Q.223 When struct is used instead of the keyword class means, what will happen in the program?
a) access is public by default
b) access is private by default
c) access is protected by default
d) none of the mentioned
Answer:a
Answer:a
Answer:c
Q.226 Which of these following members are not accessed by using direct member access operator?
a) public
b) private
c) protected
d) Both a & b
Answer:d
#include <iostream>
using namespace std;
class Box
{
public :
double length;
double breadth;
double height;
};
int main( )
{
Box Box1;
double volume;
Box1.height = 5;
Box1.length = 6;
Box1.breadth = 7.1;
volume = Box1.height * Box1.length * Box1.breadth;
cout << "Volume of Box1 : " << volume <<endl;
return 0;
}
a) 210
b) 213
c) 215
d) 217
Answer:b
Answer:a
Answer:d
Answer:d
#include <iostream>
using namespace std;
class sample
{
private:
int var;
public:
void input()
{
cout << var;
}
void output()
{
cout << "Variable entered is ";
cout << var << "\n";
}
};
int main()
{
sample object;
object.input();
object.output();
object.var();
return 0;
}
a) Enter an integer 5
Variable entered is 5
b) runtime error
c) error
d) none of the mentioned
Answer:c
Answer:a
Answer: a
#include <iostream>
using namespace std;
class number
{
int i;
public:
int geti();
void puti(int j);
};
int number::geti()
{
return i;
}
void number::puti(int j)
{
i = j;
}
int main()
{
number s;
s.puti(10);
cout << s.geti( );
return 0;
}
a) 10
b) 11
c) 20
d) 22
Answer:a
Answer:a
Answer:b
Answer:b
Q.238 What is the output of this program? 2 Marks
#include <iostream>
using namespace std;
class p
{
protected:
int width, height;
public:
void set_values (int a, int b)
{
width = a; height = b;
}
virtual int area (void) = 0;wa
};
class r: public p
{
public:
int area (void)
{
return (width * height);
}
};
class t: public p
{
public:
int area (void)
{
return (width * height / 2);
}
};
int main ()
{
r rect;
t trgl;
p * ppoly1 = ▭
p * ppoly2 = &trgl;
ppoly1->set_values (4, 5);
ppoly2->set_values (4, 5);
cout << ppoly1 -> area() ;
cout << ppoly2 -> area();
return 0;
}
a) 1020
b) 20
c) 10
d) 2010
Answer:d
#include <iostream>
using namespace std;
class MyInterface
{
public:
virtual void Display() = 0;
};
class Class1 : public MyInterface
{
public:
void Display()
{
int a = 5;
cout << a;
}
};
class Class2 : public MyInterface
{
public:
void Display()
{
cout <<" 5" << endl;
}
};
int main()
{
Class1 obj1;
obj1.Display();
Class2 obj2;
obj2.Display();
return 0;
}
a) 5
b) 10
c) 5 5
d) None of the mentioned
Answer:c
#include <iostream>
using namespace std;
class sample
{
public:
virtual void example() = 0;
};
class Ex1:public sample
{
public:
void example()
{
cout << "ubuntu";
}
};
class Ex2:public sample
{
public:
void example()
{
cout << " is awesome";
}
};
int main()
{
sample* arra[2];
Ex1 e1;
Ex2 e2;
arra[0]=&e1;
arra[1]=&e2;
arra[0]->example();
arra[1]->example();
}
a) ubuntu
b) is awesome
c) ubuntu is awesome
d) None of the mentioned
Answer:c
#include <iostream>
using namespace std;
class Base
{
public:
virtual void print() const = 0;
};
class DerivedOne : virtual public Base
{
public:
void print() const
{
cout << "1";
}
};
class DerivedTwo : virtual public Base
{
public:
void print() const
{
cout << "2";
}
};
class Multiple : public DerivedOne, DerivedTwo
{
public:
void print() const
{
DerivedTwo::print();
}
};
int main()
{
Multiple both;
DerivedOne one;
DerivedTwo two;
Base *array[ 3 ];
array[ 0 ] = &both;
array[ 1 ] = &one;
array[ 2 ] = &two;
for ( int i = 0; i < 3; i++ )
array[ i ] -> print();
return 0;
}
a) 121
b) 212
c) 12
d) None of the mentioned
Answer:b
Answer:a
Answer:a
Answer:d
Q.245 In which direction does the assignment operation will take place?
a) left to right
b) right to left
c) top to bottom
d) None of the mentioned
Answer:b
Answer:c
#include <iostream>
using namespace std;
int main ()
{
int a, b;
a = 10;
b = 4;
a = b;
b = 7;
cout << "a:";
cout << a;
cout << " b:";
cout << b;
return 0;
}
a) a:4 b:7
b) a:10 b:4
c) a:4 b:10
d) None of the mentioned
Answer:a
#include <iostream>
using namespace std;
int main ()
{
int a, b, c;
a = 2;
b = 7;
c = (a > b) ? a : b;
cout << c;
return 0;
}
a) 2
b) 7
c) 9
d) 14
Answer:b
Q.249 What is the output of this program? 2 Marks
#include <iostream>
using namespace std;
int main()
{
int a = 0;
int b = 10;
if ( a && b )
{
cout << "true"<< endl ;
}
else
{
cout << "false"<< endl ;
}
return 0;
}
a) true
b) false
c) error
d) None of the mentioned
Answer:b
Q.250 Where does the default parameter can be placed by the user?
a) leftmost
b) rightmost
c) both a & b
d) none of the mentioned
Answer:b
Unit 2 : Classes & Objects
Question Bank
A. Class
B. Constructor
C. Destructors
D. Attributes
Ans : A
Explanation: In class, only all the listed items except class will be declared.
2)Constructor is executed when __ _.
A. Class A { int x; };
B. Class B { }
C. Public class A { }
D. Object A { int x; };
Ans : A
A. Default
B. Break
C. Protected
D. Asm
Ans : C
A. +
B. ::
C. -
D. *
Ans : B
A. 0
B. 2
C. 4
D. 1
Ans : D
Explanation: When we create object of empty class at that time State of that object is nothing.
Behaviour of that object is also nothing, but compiler assigns a unique address to that object.
Memory in Computer is always organized in the form of bytes and minimum memory available at
object address location is 1 byte. That's why size of object of empty class is 1 byte.
8) How to access the object in the class?
A. Ternary operator
B. Scope resolution operator
C. Direct member access operator
D. None of the above
Ans : C
Explanation: Objects in the method can be accessed using direct member access operator which is
(.).
9) When struct is used instead of the keyword class means, what will happen in the program?
Explanation: Access is public by default will happen Whenstruct is used instead of the keyword
class.
10) Which of the following is not a member of class?
A. Static Function.
B. Friend Function
C. Const Function
D. Virtual Function
Ans : B
Answer: (D)
Explanation: Header file can not be passed to a function in C++. While array, constant and
structure can be passed into a function.
So, option (D) is correct.
12) Which of the following is not a correct statement?
(A) Every class containing abstract method must be declared abstract.
(B) Abstract class can directly be initiated with ‘new’ operator.
(C) Abstract class can be initiated.
(D) Abstract class does not contain any definition of implementation.
Answer: (B)
Explanation:
• Every class containing abstract method must be declared abstract. Correct Declaration is
required.
• Abstract class can directly be initiated with ‘new’ operator. No it can’t be initiated directed by
only ‘new’ operator. So, it is Inorrect
• Abstract class can be initiated.Correct
• Abstract class does not contain any definition of implementation.Correct
So, option (B) is correct.
Answer: (B)
Explanation: Every object maintains a copy of non-static data members. For example, let
Student be a class with data members as name, year, batch. Every object of student will have its
own name, year and batch. On a side note, static data members are shared among objects.
All objects share codes of all methods. For example, every student object uses same logic to find
out grades or any other method.
14) A member function can always access the data in _______ _ , (in C++).
(A) the class of which it is member
(B) the object of which it is a member
(C) the public part of its class
(D) the private part of its class
Answer: (A)
Explanation: A member function can access it’s class member variables, irrespective of the
access specifier in which the member variable is declared.So, a member function can always
access the data in the class of which it is a member.
So, option (A) is correct.
15) Data members and member functions of a class in C++ program are by default
A. protected
B. public
C. private
D. None
View Answer
Answer: C
16) Which operator is used to allocate an object dynamically of a class in C++?
A. :
A. Constructor
B. Destructor
C. Copy constructor
D. Assignment operator
E. All
Answer: E
19) When you create an object of a class A like A obj ; then which one will be called
automatically
A. Constructor
B. Destructor
C. Copy constructor
D. Assignment operator
Answer: A
20) The class in C++ which act only as a base class and object of it cannot be created is
A. parent class
B. super class
C. abstract class
D. none of the above
Answer: C
Q.004 If class A has add() function with protected access, and few other members in public.
Then class B inherits class A privately. Will the user will not be able to call __
from the object of class B.
A Any function of class A
B The add() function of class A
C Any member of class A
D Private, protected and public members of class A
Correct D
Q.005 If an abstract class has all the private members, then _
A No class will be able to implement members of abstract class
B Only single inheritance class can implement its members
C Only other enclosing classes will be able to implement those members
D No class will be able to access those members but can implement.
Correct A
Q.006 If the protected members are to be made accessible only to the nearest subclass and no
further subclasses, which access specifier should be used in inheritance?
A The sub class should inherit the parent class privately
B The sub class should inherit the parent class as protected
C The sub class should inherit the parent class as public
D The sub class can use any access modifier
Correct A
Q.007 Except constructors, if all the members are defined in protected specifier then ___
A Instance of class can’t be created
B Instance of class can be created anywhere
C Instance of class can be created only in subclasses
D Instance of class can be created only in main() function
Correct B
Q.008 If protected inheritance is used then _
A Public members become public in subclass
B Protected members become public in subclass
C Protected members become protected in subclass
D Protected and Public members become protected in subclass
Correct D
Correct C
Q.031 What is the role of a constructor in classes?
A To modify the data whenever required
B To destroy an object
C To initialize the data members of an object when it is created
D To call private functions from the outer world
Correct C
Q.032 What will be the output of the following C++ code?
A Error
UNIT II MCQ
B. Friend constructor
C. Default constructor
D. Parameterized constructor
Answer: Option B
C. Const function
D. Virtual function
Answer: Option B
5. Which of the following concepts means determining at runtime what method to invoke?
A. Data hiding
B. Dynamic Typing
C. Dynamic binding
D. Dynamic loading
Answer: Option C
6. Which of the following term is used for a function defined inside a class?
A. Member Variable
B. Member function
C. Class function
D. Classic function
Answer: Option B
7. Which of the following concept of oops allows compiler to insert arguments in a function
call if it is not specified?
A. Call by value
B. Call by reference
C. Default arguments
D. Call by pointer
Answer: Option C
B.5
C. 13
D. 0
B. Class
C. Object
D. Operator function
Answer: Option C
Answer: Option a
13. True/False: A class can serve as base class for many derived classes.
Answer: True
14. When a class serves as base class for many derived classes, the situation is called:
a. polymorphism
b. hierarchical inheritance
c. hybrid inheritance
d. multipath inheritance
e. none of these
Answer: (b)
15. When two or more classes serve as base class for a derived class, the situation is known as
_ .
a) multiple inheritance
b) polymorphism
d) hierarchical inheritance
e) none of these
Answer: (a)
16. Which of the following statement is correct?
A. A constructor is called at the time of declaration of an object.
Answer: Option A
D. Initialize objects
Answer: Option D
21. Which of the following is correct about the statements given below?
All operators can be overloaded in C++.
We can change the basic meaning of an operator in C++.
A. Only I is true.
C. Only II is true.
D. Both I and II are true.
Answer: Option B
22. What happens if the base and derived class contains definition of a function with same
prototype?
A. Compiler reports an error on compilation.
B. Multilevel
C. Distributive
D. Hierarchical
Answer: Option C
D. Both A and C.
Answer: Option D
B. ->
C. ?:
D. *
Answer: Option C
B. operator
C. friend
C. Hybrid inheritance
D. Hierarchical Inheritance
Answer: Option B
32. Which of the following is an invalid visibility label while inheriting a class?
A. public
B. private
C. protected
D. friend
Answer: Option D
C. Dynamic binding
D. Encapsulation
Answer: Option B
35. When a function is defined inside a class, this function is called ………….
A) Inside function
B) Class function
C) Inline function
D) Interior function
Answer B) +
39. Which of the following is true about the static member variable in C++.
i) It is initialized to zero when the first object of its class is created. Other initialization is also
permitted.
ii) It is visible only within the class, but its lifetime is the entire program.
A) i-True, ii-True
B) ii-False, ii-True
C) i-True, ii-False
D) i-False, iii-False
40. Which of the following keywords are used to control access to a class member?
A) default
B) break
C) protected
D) goto
Answer C) protected
41. What will be the values of x, m and n after execution of the following statements?
Int x, m, n;
m=10;
n=15;
x= ++m + n++;
43. A variable is defined within a block in a body of a function. Which of the following are true?
A) It is visible throughout the function.
B) It is visible from the point of definition to the end of the program.
C) It is visible from the point of definition to the end of the block.
D) It is visible throughout the block.
48. Constructor is
A. A class automatically called whenever a new object of this class is created
B. A class automatically called whenever a new object of this class is destroyed
C. A function automatically called whenever a new object of this class is created
D. A function automatically called whenever a new object of this class is destroyed
Answer: Option C
51. What happens when we try to compile the class definition in following code snippet?
C. It will not compile because a class cannot be protectedly inherited from other class.
Answer: Option D
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.
Answer: Option D
Answer: Option D
Answer: Option B
57. 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
58. Which of the following statements is correct about the constructors and destructors?
Answer: Option B
59. 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
60. 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.
Answer: Option B
61. Which of the following keywords is used to control access to a class member?
B. Break
C. Protected
D. Asm
Answer: Option C
73.. What is required in inheritance to initialize the data members of the base class through derived
class?
A) Object declaration
B) Destructor
C) Constructor
D) Inheritance
Answer:C) Constructor
75. Which of the statements is true in a protected derivation of a derived class from a base class?
A) Private members of the base class become protected members of the derived class
B) Protected members of the base class become public members of the derived class
C) Public members of the base class become protected members of the derived class
D) Protected derivation does not affect private and protected members of the derived class
76. When the access specifier of the base class in the derived class definition is public, the base
class is ..
A) Publicly inherited
B) Protectedly inherited
C) Privately inherited
79. The constructor and the destructor of a class are automatically invoked when memory is
allocated and deallocated to an ....
A) Data type
B) Copy constructor
C) Object
Answer:C) Object
A) has no body
B) returns nothing
A) Nested Class
B) Inheritance
C) Containership
D) Encapsulation
Answer:A) Nested Class
A) Reference
B) Pointer
C) Array
Answer:B) Pointer
Answer:a
Explanation:Because array variable and values need to be declared after the datatype only.
84. What is the index number of the last element of an array with 9 elements?
a) 9
b) 8
c) 0
d) Programmer-defined
Answer:b
Explanation:Because the first element always starts at 0. So it is on 8 position.
Answer:a
Explanation:None.
86. Which of the following accesses the seventh element stored in array?
a) array[6];
b) array[7];
c) array(7);
d) array;
Answer:a
Explanation:The array location starts from zero, So it can accessed by array[6].
87. Which of the following gives the memory address of the first element in array?
a) array[0];
b) array[1];
c) array(2);
d) array;
Answer:d
#include <stdio.h>
using namespace std;
int array1[] = {1200, 200, 2300, 1230, 1543};
int array2[] = {12, 14, 16, 18, 20};
int temp, result = 0;
int main()
{
for (temp = 0; temp < 5; temp++) {
result += array1[temp];
}
for (temp = 0; temp < 4; temp++) {
result += array2[temp];
}
cout << result;
return 0;
}
Answer:b
Explanation:In this program we are adding the every element of two arrays. Finally we got output
as 6533.
Output:
$ g++ array.cpp
$ a.out
6533
#include <stdio.h>
using namespace std;
int main ()
{
int array[] = {0, 2, 4, 6, 7, 5, 3};
int n, result = 0;
for (n = 0; n < 8; n++) {
result += array[n];
}
cout << result;
return 0;
}
a) 25
b) 26
c) 27
d) None of the mentioned
Answer:d
Explanation:We are adding all the elements in the array and printing it. Total elements in the
array is 7, but our for loop will go beyond 7 and add a garbage value.
#include <stdio.h>
using namespace std;
int main()
{
a) ABC
b) ABCD
c) AB
d) None of the mentioned
Answer:a
Explanation:We are just printing the values of first 3 values.
$ g++ array.cpp
$ a.out
ABC
A. Classname Objectname;
B. Class Classname Objectname;
C. Class Classname Object Objectname;
D. Classname Object Objectname;
Answer: Option A
A. May be declared
B. Can be initialized
C. Cannot be intialized
D. Cannot be declared
Answer: Option D
1 Which of the following term is used for a Member Variable Member function Class function Classic function
function defined inside a class?
2 Classes are useful because they are removed from permit data to be hidden bring together all aspects can closely model
memory when not in use from other classes of an entity in one place objects in the real
world
3 Which member function of class cannot friend functions Private member functions Constant member Static member
modify its objects attributes ? functions functions
4 Which of the following is an abstract data int double string Class
type?
5 Which of the following statement is correct? Object is an instance of a Class is an instance of data Object is an instance of Class is an instance
class. type. data type. of object
6 Which of the following is correct about class class can have member class data members are Pointer to structure or class data members
and structure? functions while structure public by default while classes cannot be are private by
cannot. that of structure are private declared. default while that of
structure are public
by default.
7 What does your class can hold? Data Functions Both A & B None of the above
8 What is object in C++ ? Object is function of a Object is an instance of a Object is datatype of a Object is part of
class. class. class. syntax of a class
9 How many specifier are present as access 1 2 3 4
specifier in a class in C++?
10 Which operator is used to define the member : :: # None Of The
of a class externally? Mentioned
11 Which of the following is a valid class class A { int x; }; class B { } public class A { } object A { int x; };
declaration?
12 The fields in the class in c++ program are by protected private public none of the
default mentioned
13 What is class in c++ ? When you define a class, When you define a class, A. When you define a When you define a
you define a blueprint for you add more class, you define class, you make
a data type functionality. the logic. debugging.
20 The new operator returns a pointer to the creates a variable called obtains memory for a tells how much
variable new new variable memory is
available
24 ::count means ----- Local version of the Global version of the Both local and global All of these
variable count variable count version of count
25 The scope resolution operator is a semicolon(;) a colon(:) two colons(::) a comma(,)
37 Instead of the class if use struct then _ _. access in the public by access is private by default access is protected by none of these
default default
38 choose the correct statement. only data members are only member functions both data and member . the member
private are public functions can be public functions are private
39 Which of the following is not validity access public private protected extern
specifier in the class ?
40 A class cannot be _ _. virtual friend generic inline
41 What is the purpose of keyword inline? it allows one line function . it causes the replacement it indicates the function it tells compiler to
declaration of function calls by the declaration use that function in
code from the function the same source
code file
42 Which of the following is a valid inline public private protected extern
function 'myfun'?
43 inline void myfun() void myfun() inline inline:: void none of these
{//functon code} {//function code} myfun{//function code}
44 Following is a main benefit of the inline it decrease the size of the it simplifies the source it increases the speed of it removes
function/ program code the resulting program unnecessary
function
45 Following is a limit on inline function. inline function can not inline function has to inline function must have the compiler can
return a values return a value less than 10 lines of code choose to ignore an
inline directive.
46 When will you make a function inline? if that function is small . if the function is small if the function is not if the function is not
and not called frequently but called frequently small but called small and not called
frequently frequently
47 The fields in class of C++ program are _ _. . public private protected none of these
48 Which of the following keyword is used to const switch private for
control the access of data members of a class
?
49 What arrays in the C++? . A series of elements of A series of elements of A series of elements of A series of elements
same type placed in different type placed in same type placed in non- of different type
continuous block of continuous block of continuous block of placed in non-
memory memory memory continuous block of
memory
50 The memory address for array can be obtained a[0] address_of(a) a[1] a
using .
51 What is the output of the following code? 42 30 garbage value syntax error
#include <iostream>
using namespace std;
class Test
{
private
int array[]={0,2,4,6,8,10,12};
public:
void computer();
};
void Test::compute()
{
int result=0;
for (int i=0;i<7;i++)
{
result+=array[i];
}
cout<<result;
}
int main()
{
test obj;
obj.compute();
return();
}
52 The size of heap memory is _ _. 100 MB 1024 MB 1024 GB determined by size
of RAM and swap
memory
53 How will you pass the large objects in C++? using call by value using call by reference either a or b none of these
method method
54 Objects of the same class shres the values of global variables and static non static and static static variables, non static local and static
_ and maintain separate values for _. variables variables
55 Which of the member functions of class private member functions constant member functions friend function static member
cannot modify its objects attributes ? function
56 How many types of classes are there? 1 2 3 4
57 How to access object in the class? using ternary operator using direct member scope resolution operator none of these
access operator
58 Constructors are used . to build a user interface deallocate memory initialize newly created to construct
objects functions
59 Which of the following member is not public private protected both B and C
accessible using the direct member access
operator?
60 If different objects are created the separate data members member functions both A ans B none of these
memory space is created for .
61 The memory required by any objects is size of non static data order of data members Byte padding all of these
dependent upon following factors members of the class
62 Which of the following is correct way of Class_name object_name; object_name class_name class class_name class class_name
declaring object of a class ? object_name object object_name
63 What is the output of the following code? 10 constructor invoked syntax error none of these
#include<iostream>
using namespace std;
class test
{
private:
int a;
public:
test(int x);
};
test::test(int x=10)
{
a=x;
cout<<"\n Constructor Invoked";
}
int main()
{
test obj1,*obj2;
return 0;
}
64 How many objects can be created by a single 1 2 3 as many as required
class?
65 The name of the constructor is . limited to 10 character same as the belonging main as per the
class name programmer's choice
66 What is the output of the following code? Constructor syntax error constructor copy constructor
#include <iostream> copy constructor copy constructor copy constructor
using namespace std; copy constructor constructor copy constructor
class test
{
private:
int a;
public:
test(int x);
test(test &);
};
test::test(int x=10)
{
a=x;
cout<<"\n CopyConstrustor";
}
int main()
{
test*obj1,*obj2;
obj1=new test (10);
obj2=new test(*obj1);
test *obj3;
obj3=new test(20);
return 0;
}
67 What is the output of the following code? 012 000 three garbage values syntax error
#include<iostream> .
using namespace std;
class test
{
private:
int a;
public:
test(int x)
void display();
};
test::test(int i)
{
a=i;
}
void test::display()
{
cout<<""<<a;
}
int main()
{
test obj[3];
obj[0].display();
obj[1].display();
obj[2].dispaly();
return 0;
}
68 What is the output of the following code? constructor constructor constructor destructor constructor constructor no output
#include<iostream> destructor destructor
using namespace std;
class test
{
private:
int a;
public:
test()
{
a=0;
cout<<"constructor";
}
~test()
{
cout<<"destructor";
}
};
int main()
{
test a[2];
return 0;
}
69 What is the output of the following code? 0 1 garbage value syntax error
#include<iostream>
using namespace std;
class test
{
private:
int a;
public:
test()
{
a=0;
count++;
}
void display()
{
cout<count;
}
};
int main()
{
test obj;
obj.display();
return 0;
}
70 What will be the output of the following syntax error nothing will be displayed Constructor destructor Constructor
code? constructor
class test
{
public:
test()
{cout< "constructor";}
~test()
{cout< "destructor";}
};
int main()
{
delete new test();
return 0;
}
71 The default constructor accepts _ one two three no
parameters.
72 If the default constructor is not defined then . it will cause syntax error it will cause runtime error the compiler will create none of these.
_ _ constructor for creating
an object
73 A class is not having default constructor but the desired object will get it will cause syntax error it will cause runtime error none of these
one parameterized constructor. created because compiler
We have created an object that needs zero will create an inplicit
argument constructor. What will happen in default constructor.
this case?.
74 The destructor is preceded by the symbol # ! ~ $
_
75 The constructors and destructors for an by making explicit call to when object enters and when inheritance occurs none of these
automatic object are invoked . constructor and destructor leaves its scope
functions
76 For copying the object of same class type default constructor dynamic constructor when inheritance occurs none of these
following type of constructor is defined
_
77 Which of the following is true about only I I,III and IV I and II I,II and III
constructor?
I. Constructor have same name as its class
name.
II. They constructors can be inherited
III. The constructor cannot be declared in
protected section.
IV. Constructor cannot return values.
78 Which of the following is not true about only I I and II I and III I,II and III
destructor?
I. It is preceded by dollar sign
II. It can be declared in private section
III. It can be parameterized
79 Object can be defined as _. attribute of class instance of a class member of a class none of these
80 The copy constructor _. creates an object from creates an object from an creates an object which is none of these
any object. object of same class pointer to copied object
81 For initializing the data members of class data members get creates an object from an creates an object which is none of these
_ _ is used. initialized automatically object of the same class. pointer to copied object
in C++
82 For initializing the data members of class _ data members get constructor destructor none of these
is used. initialized automatically
in C++
83 A class can have . all the constructors that only parameterized and only copy constructors only parameterized
are required copy constructors constructors
84 Which of the following statement is correct ?
A. constructors can have default parameters.
B. constructor cannot have default parameters.
C. constructor cannot have more than one
default parameters.
D. At the most 3 default parameters are
allowed for constructor.
ANSWER: A
85 Which constructor will execute in following constructor 1 constructor 2 constructor 3 syntax error
code?
class test{
public:
int a,b;
test(){a=b=1;}
test(int a){a=a;b=1;}
test(int a,int b){a=a;b=b;}
}
int main()
{
test obj(1,2);
return 0;
}
86 What value should destructor return ? status code that indicates pointer to class destructor does not return object of a class
that allocated memory for any value
object is freed.
87 Which of the following is nota type of default constructor parameterized constructor copy constructor public constructor
constructor?
88 Which of the following statement will invoke TEST T1(T2) T1=new Test(); T1=T2 none of these
copy constructor for class TEST?
89 Operator overloading is _. technique to work with technique which allows making new C++ giving new relevent
objects C++ to handle more than operators meaning to existing
one operators C++ operators
without changing
basis meaning
90 Operator function is created using _ allocator . constructor operator iterator
keyword.
91 How tp declare operator function ? operator function_name operator operator_sign() operator_sign none of these
92 Which of following operator cannot be + - :: []
overload?
93 Operator function must be _ . only 1 1 and 3 2 and 3 All 1,2 and 3
1. Non-static member function 2. Static
function 3. friend function
94 In C++ _ _ operator is used for dynamic Scope resolution operator conditional operator new arithmetic operator
memory allocation. +
95 While overloading binary operator using Zero argument one argument two arguments it depends upon the
member function it requires . operator to be
overloaded
96 What will be the output of the following 30 3 00 11 22 22 11
code?
99 Which of the following is a type of data members member function . both A and B none of these
inheritance?
100 Which of the following is a type of single inheritance and single and multiple Single ,multiple, single, multiple,
inheritance? multilevel inheritance inheritance multilevel inheritance multilevel
,hierarchical and
hybrid inheritance
]
101 In relationship an object of derived class encapsulation . polymorphism inheritance none of these
can also be treated as an object of its base
class.
102 For deriving the child class from the base :: : ; ->
class which symbol is used?
103 What will be output of following code? syntax error 55.55 10 10 55.55 55.55
Class A
{
public:
A(int n)
{
cout<<n;
}
};
class B:public A
{
B(int n,double d):A(n)
{
cout<<""<<d;
}
};
int main()
{
B b(10 ,55.55);
return 0;
}
104 What will be the output of the following 10 A 11.11 A 11.11 10 A 11.11
code?
Class A
{
public:
A(int x)
{
cout<<x;
}
};
class B: public A
{
public:
B(int x,char y):A(x)
{
cout<<" "<<y;
}
};
class C:public B
{
public:
C(int x,char y,double z) :B(x,y)
{
cout<<" "<<z;
}
};
int main()
{
C c(10,'A’,11.11);
return 0;
}
105 When an object of derived class is instantiated base class constructor derived class constructor not allowed to instantiate none of these
the _ is called explicitly or implicitly. derived class constructor
106 Class b is derived from class A then it is Single inheritance Multiple inheritance Multilevel inheritance Hybrid inheritance
called____
107 Class C is derived from class B and class B is Single inheritance Multiple inheritance Multilevel inheritance Hybrid inheritance
derived from class A then it is called .
108 Class D is derived from class Base 1 and Single inheritance Multiple inheritance Multilevel inheritance Hybrid inheritance
Class Base 2 then it is called _ _.
109 Class A,B,ansC are derived from class Single inheritance Multiple inheritance Multilevel inheritance Hybrid inheritance
Base2then it is called __ .
110 What will be the output of the following 100 0 syntax error none of these
code?
class A
{
private:
int x;
protected:
int y;
public:
int z;
};
class B:public A
{
};
int main()
{
B b;
b.x=100;
cout<<b.x;
return 0;
}
111 When base class is derived in protected mode only 1 ,5 only 2,4 only 1,6 only 2,6
then .
1. public members of base class become
private members of derived class.
2. public member of the base class become
proctected members of derived class
3. public members of base class become
public members of derived class.
4. protected members of base class become
proctected members of derived class.
5. protected members of base class become
private members of derived class.
6. protected members of base class become
public members of derived.
112 When deriving a class with public inheritance, Public, public Public, private public ,protected protected ,private
public members of the base class become
members of the derived class and protected
members of the base class become
members of the derived class.
113 If the class is derived using protected mode public members private members protected none of these
then public members of the base class become
_ of derived class.
114 If the class is derived using protected mode public members private members protected none of these
then protected members of the base class
become _ of derived class.
115 If the class is derived using protected mode public members private members protected none of these
then private members of the base class
become _ of derived class.
116 What will be the output of the following x=10,y=20,z=30 error for x,y=20,z=30 error for x and y,z=30 error for x,y and z
code?
class A
{
private:
int x;
protected:
int y;
public:
int z;
};
class B:protected A
{
public:
void display()
{
x=10;
y=20;
z=30;
}
};
117 If a class is derived using private mode then public members private members protected none of these
public members of base class become _ of
derived class.
118 If a class is derived using private mode then public members private members protected none of these
protected mode members of base class
become _ _ of derived class
119 If a class is derived using private mode then public members private members protected none of these
private mode members of base class become
_ _ of derived class
120 What will be the output of the following x=100,y=200,z=300 error for x,y=200,z=300 error for x and y,z=300 error for x,y and z
code?
class A
{
private:
int x;
protected:
int y;
public:
int z;
};
class B:private A
{
public:
void display()
{
x=100;
y=200;
z=300;
}
};
121 What will be the output of the following The value of x,y and z are error for assigment of x error for assignment of x error for accessibilty
code? assigned as 10,20,30 and y of display ()
class A respectively function
{
private:
int x;
protected:
int y;
public:
int z;
void display()
{
x=10;
y=20;
z=30;
}
};
class B:private A
{
};
int main()
{
B b;
b.display();return 0;
}
122 During class inheritance if the visibility mode public private protected none of these
of derivation is not specified then the default
visibility mode is _ .
123 What is the difference between protected and private member is not protected member is both are inheritable but both are inheritable
private access specifier ? inhertiable and not inheritable and also private is accessible inthe but protected is not
accessible in derived accessible in derived class derived class accessible in the
class derived class.
124 If a derived class is struct then its visibiltiy public private protected . cannot inherit
mode is _ . structure
125 The constructors for both derived and base only the constructor of only the constructor of the constructor of base the constructor of
class are defined .using the main the object off derived class will be base class will be invoked. class will be invoked and derived class will be
derived class is created . invoked then the constructor of invoked and then the
In such a situation _. derived class will be constructor of base
invoked class will be invoked
126 What will be the output of the following base class constructor derived class constructor base class constructor derived class
code? derived class constructor constructor base
class A class constructor
{
public:
A()
{
cout<<"base class
construtor";
}
};
class B:public A
{
public:
B()
{
cout<<"Derived Class
Constructor";
}
};
int main()
{
B b;
return 0;
}
127 If we define a base class constructor with optional compusory depends upon the it will generate
arguments then it is _ for derived class to compiler syntax error because
have constructor and pass argument to base paramerized
class constructor. constructor is not
allowed in base class
128 What will be the output of the following . B_constructor B_constructor B_constructor Run time error
code? D_constructor D_constructor B_destructor
Class A D_destructor B_destructor D_constructor D_
129 Which of the following is/are valid ways . int *p = new int(100); int *p; p = new int; *p = int *p = NULL; p = All of these
to allocate memory for an integer by 100; new int; *p=100;
dynamic memory allocation in CPP?
130 During dynamic memory allocation in False NULL Zero None of these
CPP, new operator returns _
value if memory allocation is
unsuccessful.
131 When the memory spaces for the member when the objects are when the class are when member All of these
functions are allocated? created created functions are defined as
a part of class
132 Why separate memory locations are member variables hold each object in the class Both a,b none of these
essential for an object different data values for has separate member
different objects function
133 The amount of memory allocated for an amount of memory amount of memory amount of memory amount of memory
object is equal to required by member required by data required by both data required by the
functions of that class members of that class members and data class
functions
134 All the objects of a class share the same data members member functions both data members and None of these
copy of member function
135 How will you free the memory allocated delete(p) delete p delete(int p) delete (p,0)
by the following program?
#include <iostream>
using namespace std
int main()
{
int *p;
p=new int;
return 0;
}
136 When the memory spaces for the data when the class is when the object of the when the member None of these
member are allocated? specified class is declared function is declared
137 How much memory will be allocated to 8Bytes 7Bytes 6Bytes No memory will
the object obj1 of the following class? be allocated
class test
{
float a;
int b;
char c;
}
int main()
{
test obj1;
return 0;
}
138 What are arrays in the C++? . A series of elements A series of elements of A series of elements of A series of
of same type placed in different type placed in same type placed in elements of
continuous block of continuous block of non-continuous block different type
memory. memory of memory placed in non-
continuous block
of memory.
139 The memory address for array can be a[0] address_of(a) a[1] a
obtained using _ _.
140 Which of the following are characteristics The array contains all All the elements of the The name of the array All of the above
of array? the elements of same array share the same represents the address
data type name and then can be of the first element of
distinguished from one an array
another by index
141 How will you pass the large objects in using call by value using call by reference either a or b none of these
C++? method method
142 Which of the following correctly declares int array[10]; int array; array{10}; array array[10];
an array?
143 What is the index number of the last 9 8 0 Programmer-
element of an array with 9 elements? defined
144 The process of storing the elements in an initialization of array declaration of array finalization of array none of the above
array is called as
145 Which of the following correctly declares ABC array[10]; ABC array; array{10}; array array[10];
an array of objects for a class ABC?
146 How much memory will be allocated to 10Bytes 20Bytes 40Bytes No memory is
the object obj1 in the following code? allocated
#include<iostream>
using namespace std;
class student
{
int age;
int roll_no;
public:
………
....……
};
int main()
{
student s[10];
………..
………..
return 0;
}
147 What will be the output of the following 30and3 0and0 11and 22 22and11
code?
vector vector::operator+(vector obj)
{
vector temp;
temp.p=p+obj.p;
temp.q=q+obj.q;
return (temp);
}
int main()
{
vector a(10,20);
vector b(1,2);
vector c;
c=a+b;
cout<<c.p<<”and”<<c.q;
return 0;
}
148 Which of the following statements are only 1 and 2 only 3 and 4 All of the above None of the above
true for operator overloading?
1. Only existing operators can be
overloaded
2. The overloaded operator must have at
least one operand that is of user defined
type.
3. Overloaded operators follow the syntax
rules of the original operators.
4. Binary arithmetic operators such as +,-
,* and / must explicitly return a value.
149 Which is the correct function prototype complex complex complex complex
declaration for overloading the ‘+’ operator+(complex); operator++(complex); operator+(complex) operator(complex);
operator in class ‘complex’?
150 Inheritance is ............... in nature. Intransitive Transitive Both (a) & (b) None of the above
151 The result of the following statement is ans=7, y=7 ans=8,y=7 ans=8,y=8; none of the above
int y = 7;
int ans = ++y;
cout<<”ans=”<<ans;
cout<<”y”<<y;
152 What is the output of the following code? Error The result of addition The result of addition The result of
#include<iostream> is:16 is:sum(); addition is:
using namespace std;
class test
{
int a,b;
public:
test(int x, int y)
{
a=x; b=y;
}
int sum();
void display();
};
int test::sum()
{
return a+b;
}
void test::display()
{
cout<<”\nThe result of addition
is:”<<sum();
}
void main()
{
test obj1(7,9);
obj1.display();
return 0;
}
153 A constructor function is ___ A friend function to a A member function with A non-member None of the above
class the same name as its function
class
154 A constructor function is generally In the public section of In the private section of In the protected section None of the above
defined __ a class a class of a class
155 A class having no public constructors is A private class A public class An abstract class None of the above
__
156 If a constructor function is defined in The object cannot be Only member functions Both (a) & (b) None of the above
private section of a class, then created and friends may declare
__ objects of the class
157 A constructor with no argument is Default constructor Parameterized Copy constructor None of the above
__ _ constructor
158 If arguments are provided to a constructor Default constructor Copy instructor Parameterized None of the above
159 The parameterized constructor Needs initial values as Can be invoked Can be invoked None of the above
__ arguments during explicitly only implicitly only
creation of an object
160 Given a class named Book, which of the Book ( ) { } Book ( Book b) { } Book ( Book &b) { } Book (char*
following is not a valid constructor? author, char* title)
{}
161 Which of the following statements A constructor may be Constructor can have Member functions may None of the above
regarding constructor is false? defined static default arguments be invoked from within
a constructor
162 A destruction function Takes no argument and Has name similar to that Is used to destruct an All of the above
has no return type not of class, preceded by object, constructed
even void tilde(~) symbol through constructor
function
163 Destructors are called __ _ in the same order of in the reverse order of in any random order none of the above
constructor calls constructor calls
164 Constructors are used _ to build a user interface deallocate memory initialize newly created to construct
objects functions
165 If a default constructor is not defined then it will cause syntax ) it will cause runtime the complier will create none of these
__ . error error constructor for creating
an object
166 How many constructors can a class have? 0 1 2 any number
167 Which of the following is not the They should be They do not have return They can not be They can be
characteristic of constructor. declared in the public type. inherited virtual.
section.
168 In which case is it mandatory to provide a Almost in every class Class for which two or Class for which copy Class whose
destructor in a class? more than two objects constructor is defined objects will be
will be created created
dynamically
169 Class function which is called Constructor Destructor Friend function Inline function.
automatically as soon as the object is
created is called as __
170 Complement of the constructor is Overloading Inheritance Polymorphism Destructor
171 If c1 and c2 are objects of class complex Sum is : 12+i2 Sum is : 5+i4 Sum is : 7-i2 syntax error
and c1=5+i4 and c2=7-i2 then what is the
output of the following program?
#include <iostream>
#include <math.h>
using namespace std;
class complex
{
int real,img;
public:
void display()
{
if(img>0)
cout<<real<<"+i"<<img<<endl;
else
{
cout<<real<<"-i"<<-
img<<endl;
}
}
complex operator+(complex);
};
complex complex :: operator+(complex c2)
{
complex sum;
sum.real = real+c2.real;
sum.img = img+c2.img;
return (sum);
}
int main()
{
complex c1,c2,ans;
ans = c1+c2;
cout<<"Sum is : ";
ans.display();
return 0;
}
172 An array name is a _____ Subscript formal parameter memory address prototype
174 Declaration of a pointer reserves memory for the object for the pointer both for the object and None of these.
space the pointer
175 Identify the operator that is NOT used -> & * >>
with pointers
176 An array element is accessed using a FIFO approach an index number the operator member name
177 The address of a variable temp of type *temp &temp float& temp float temp&
float is
178 Identify the correct sentence we cannot create the we can create the Array we can use reference to none of the
regarding inequality between reference array of reference. of reference reference mentioned
and pointer.
179 Functions can return_ _ Arrays References Objects All of above
1. Which of the following term is used for a function defined inside a class?
A. Member Variable
B. Member function
C. Class function
D. Classic function