CS304 MidTerm File by Talha Sajid
CS304 MidTerm File by Talha Sajid
Whatsapp 0328-4090195
Mid-Term CS304(Object Oriented Programming) Page 2 of 50
1. Inheritance is a way to
a) organize data.
b) pass arguments to objects of classes.
c) add features to existing classes without rewriting them.
d) improve data-hiding and encapsulation.
3. To convert from a user-defined class to a basic type, you would most likely use
a) a built-in conversion operator.
b) a one-argument constructor.
c) an overloaded = operator.
d) a conversion operator that‘s a member of the class
4. What problem(s) may occur when we copy objects without using deep copy constructor?
a) Dangling pointer
Whatsapp 0328-4090195
Mid-Term CS304(Object Oriented Programming) Page 3 of 50
b) Memory Leakage
c) System crash
d) All of the given
8. a‘A static member function can be called, even when a class is not __________.
a) Declared
b) Define
c) Instantiated
d) Called
Whatsapp 0328-4090195
Mid-Term CS304(Object Oriented Programming) Page 4 of 50
11. Which one of the following features of OOP is used to derive a class from another?
a) Encapsulation
b) Polymorphism
c) Data hiding
d) Inheritance
13. _____, which means if A declares B as its friend it does NOT mean that A can access
private data
of B. It only means that B can access all data of A.
a) Friendship is one way only
b) Friendship is two way only
c) NO Friendship between classes
Whatsapp 0328-4090195
Mid-Term CS304(Object Oriented Programming) Page 5 of 50
15. The statement objA=objB; will cause a compiler error if the objects are of different
classes.
a) True
b) False
Whatsapp 0328-4090195
Mid-Term CS304(Object Oriented Programming) Page 6 of 50
b) Assignment operator ( = )
c) Script operator ( [] )
d) Conditional operator (? : )
18. To convert from a user-defined class to a basic type, you would most likely use
a) a built-in conversion operator.
b) a one-argument constructor.
c) an overloaded = operator.
d) a conversion operator that’s a member of the class.
19. Assume a class C with objects obj1, obj2, and obj3. For the statement obj3 = obj1 - obj2
to work correctly, if the overloaded - operator must
a) take two arguments.
b) return a value.
c) create a named temporary object.
d) take four arguments
20. The keyword that is used that the variable can not change state?
a) static
b) const
c) friend
d) private
21. The technique in which we visualize our programming problems according to real life’s
problems is called____________
Whatsapp 0328-4090195
Mid-Term CS304(Object Oriented Programming) Page 7 of 50
a) structured programming
b) object oriented Programming
c) procedural programming
d) none of the given
22. In object orientated programming, a class of objects cans _____ properties from another
class of objects
a) Utilize
b) Borrow
c) Inherit
d) Adopt
23. Suppose obj1 and obj2 are two objects of a user defined class A. An + operator is
overloaded to add obj1 and obj2 using the function call obj1+obj2. Identify the correct
function prototype against the given call?
a) A operator + ( A &obj);
b) int + operator();
c) int operator (plus) ();
d) A operator(A &obj3);
24. A member function having the same name as that of a class and a ~ sign with it is called,
a) Constructor
b) Getter
c) Setter
d) Destructor
Whatsapp 0328-4090195
Mid-Term CS304(Object Oriented Programming) Page 8 of 50
26. Suppose that the Test class does not have an overloaded assignment operator. What
happens when an assignment a=b; is given for two Test objects a and b?
a) The automatic assignment operator is used
b) The copy constructor is used
c) Compiler error
d) Run-time error
30. The ____ relationship indicates that an object contains other objects.
a) ‘has-a’
Whatsapp 0328-4090195
Mid-Term CS304(Object Oriented Programming) Page 9 of 50
b) ‘is-a’
c) ‘be-
d) None of given
32. For classes with common behavior, you can save effort by placing the common behavior
in a __________.
a) Derived Class
b) Base class
c) Deprived Class
d) Named class
Whatsapp 0328-4090195
Mid-Term CS304(Object Oriented Programming) Page 10 of 50
d) all of the given
38. In order to free the memory occupied by the object, we use -------------
a) Constructor
b) Destructor
c) Shallow Copy
d) Deep Copy
Whatsapp 0328-4090195
Mid-Term CS304(Object Oriented Programming) Page 11 of 50
40. We can use "this" pointer in the constructor in the body and even in the initialization
list of any class if we are careful,
a) TRUE
b) False
41. A generic class showing all the common attributes and a behavior of other classes
represents a very important feature in oop called --------
a) Inheritance
b) Encapsulation
c) Polymorphism
d) Abstraction
42. We can get only one unique value which can be used by all the objects of that class by
the use of,
a) static variables
b) dynamic variables
c) instance variables
d) data members
Whatsapp 0328-4090195
Mid-Term CS304(Object Oriented Programming) Page 12 of 50
45. Static variables act like a global variable in the context or scope of the class.
a) True
b) False
46. The compiler won‘t object if you overload the * operator to perform division.
a) True
b) False
Whatsapp 0328-4090195
Mid-Term CS304(Object Oriented Programming) Page 13 of 50
c) User Defined Type
d) None of the given
49. Suppose there is an object of type Person, which of the following can be considered as
one of its attributes
a) Name
b) Age
c) Work()
d) Both Name and Age
50. The members of a class that can be accessed without creating the object of the class is
called________
a) Private member
b) Data Member
c) Public Member
d) Static
Whatsapp 0328-4090195
Mid-Term CS304(Object Oriented Programming) Page 14 of 50
b) New member functions and New friend functions
c) New constructors and destructor
d) All of given
53. C++ compiler does not allow to dynamically allocate memory for objects
a) False
b) True
Whatsapp 0328-4090195
Mid-Term CS304(Object Oriented Programming) Page 15 of 50
55. Friend class and friend function can be used as an alternate to each other
a) True
b) False
56. We capture the object attributes and behavior in Object Oriented programming
using____________
a) Class
b) Function
c) Data Members
d) Instances
58. What problem(s) may occur when we copy objects without using deep copy constructor?
a) Dangling pointer
b) Memory Leakage(Object is not deleted)
c) All of the given
d) System crash
Whatsapp 0328-4090195
Mid-Term CS304(Object Oriented Programming) Page 16 of 50
a) None of given
b) object member
c) non-member
d) data member
61. Keeping in view the principle of abstraction, which of the above information the
company needs to save as employee’s record?
a) 2, 4
b) 1, 3, 5
c) 1, 2, 3
d) 1, 2, 3, 4
Whatsapp 0328-4090195
Mid-Term CS304(Object Oriented Programming) Page 17 of 50
63. When a variable is define as static in a class then all object of this class,
a) Have different copies of this variable
b) Have same copy of this variable
c) Can not access this variable
d) None of given
64. __________remain in memory even when all objects of a class have been destroyed.
a) Static variables
b) Instance variable
c) Primitive variables
d) None of given
66. The life of sub object is not dependent on the life of master class in ___
a) Composition
Whatsapp 0328-4090195
Mid-Term CS304(Object Oriented Programming) Page 18 of 50
b) Aggregation
c) Separation
d) None of the given
68. ___________, which means if A declares B as its friend it does NOT mean that A can
access private data of B. It only means that B can access all data of A.
a) Friendship is one way only
b) Friendship is two way only
c) NO Friendship between classes
d) Any kind of friendship
69. To convert from a user-defined class to a basic type, you would most likely use
a) a built-in conversion operator.
b) a one-argument constructor.
c) an overloaded = operator.
d) a conversion operator that‘s a member of the class.
Whatsapp 0328-4090195
Mid-Term CS304(Object Oriented Programming) Page 19 of 50
b) Composition
c) Aggregation(the object can exist without master class like room and chair)
d) None of given
71. Which of the following is the way to extract common behavior and attributes from the
given classes and make a separate class of those common behaviors and attributes?
a) Generalization
b) Sub-typing
c) Specialization
d) Extension
72. The ability to derive a class from more than one class is called
a) Single inheritance
b) Encapsulation
c) Multiple inheritance
d) Polymorphism
74. If only one behaviour of a derived class is incompatible with base class, then it is:
a) Generalization
Whatsapp 0328-4090195
Mid-Term CS304(Object Oriented Programming) Page 20 of 50
b) Specialization
c) Extension
d) Inheritance
76. Consider the code below, class class1{ public: void func1(); }; class class2 : protected
class1 { }; Function func1 of class1 is ______ in class2,
a) public
b) protected
c) private
d) none of the given options
Whatsapp 0328-4090195
Mid-Term CS304(Object Oriented Programming) Page 21 of 50
b) functions and classes
c) classes and exceptions
d) programs and algorithms
81. Which of the following is the best approach if it is required to have more than one
functions having exactly same functionality and implemented on different data types?
a) Templates
b) Overloading
c) Data hiding
d) Encapsulation
Whatsapp 0328-4090195
Mid-Term CS304(Object Oriented Programming) Page 22 of 50
This is an example of partial specialization.
a) True
b) False
84. A non-virtual member function is defined in a base class and overridden in a derived
class; if that function is called through a base-class pointer to a derived class object, the
derived-class version is used.
a) True
b) False
85. In order to define a class template, the first line of definition must be:
a) template <typename T>
b) typename <template T>
c) Template Class <ClassName>
d) Class <Template T>
86. If there is a pointer p to objects of a base class, and it contains the address of an object
of a derived class, and both classes contain a nonvirtual member function, ding(), then the
statement p->ding(); will cause the version of ding() in the ___ class to be executed.
Whatsapp 0328-4090195
Mid-Term CS304(Object Oriented Programming) Page 23 of 50
a) Base
b) Derived
c) Abstract
d) Virtual
87. Non Template Friend functions of a class are friends of ____instance/s of that class.
a) All
b) One specific
c) All instances of one date type
d) None of the given options
88. Consider the code below, class class1{ public: int i; }; class class2 : public class1 { }; Then
int member i of class1 is ______ in class2,
a) public
b) protected
c) private
d) none of the given options
89. We can call base class constructor from derived class constructor,
a) From derived class constructor body
b) From the initializer list of derived class constructor
c) From any member function of derived class
d) We can not call the base class constructor
Whatsapp 0328-4090195
Mid-Term CS304(Object Oriented Programming) Page 24 of 50
a) “IS A” relationship
b) “Has A” relationship
c) “IS Special Kind of” relationship
d) None of these options
Whatsapp 0328-4090195
Mid-Term CS304(Object Oriented Programming) Page 25 of 50
94. If you define a vector v with the default constructor, and define another vector w with a
one-argument constructor to a size of 11, and insert 3 elements into each of these vectors
with push_back(), then the size() member function will return __ for v and ___ for w.
a) 11 for v and 3 for w.
b) 0 for v and 0 for w.
c) 0 for v and 3 for w.
d) 3 for v and 11 for w.
96. Sender of the message does not need to know the exact class of receiver in________.
a) Abstraction
b) Polymorphism
c) Inheritance
d) none of the given
Whatsapp 0328-4090195
Mid-Term CS304(Object Oriented Programming) Page 26 of 50
99. Two functions with same names, parameters and return type can exist in,
a) Function overloading
b) Function overriding
c) Operator overloading
d) None of the above
100. Consider the code below, class c1{ }; class c2 : public c1 { }; class c3 : public c2 { };
Then c2 is,
a) Direct base class of c3
b) Direct child class of c3
c) Direct base class of c1
d) None of these
Whatsapp 0328-4090195
Mid-Term CS304(Object Oriented Programming) Page 27 of 50
102. Which of the following is the best approach if it is required to have more than one
functions having exactly same functionality and implemented on different data types?
a) Templates
b) Overloading
c) Data hiding
d) Encapsulation
103. Assume a class Derv that is privately derived from class Base. An object of class Derv
located in main() can access
a) public members of Derv.
b) protected members of Derv.
c) private members of Derv.
d) protected members of Base.
104. When the base class and the derived class have a member function with the same name,
you must be more specific which function you want to call (using ___________).
a) scope resolution operator
b) dot operator
c) null operator
d) Operator overloading
105. Non Template Friend functions of a class are friends of ________instance/s of that class.
a) All
b) One specific
c) All instances of one date type
Whatsapp 0328-4090195
Mid-Term CS304(Object Oriented Programming) Page 28 of 50
d) None of the given options
Whatsapp 0328-4090195
Mid-Term CS304(Object Oriented Programming) Page 29 of 50
{
DocElement * p = new Paragraph();
p->Print();
}
When you run this program, it will print out a single line to the console output.
What will be in that line?
a) Generic element
b) Heading element
c) Paragraph element
d) Nothing will be printed.
108. When a virtual function is called by referencing a specific object by name and using
the dot member selection operator (e.g., squareObject.draw()), the reference is resolved at
compile time.
a) True
b) False
Whatsapp 0328-4090195
Mid-Term CS304(Object Oriented Programming) Page 30 of 50
b) template <typename U>
c) Class<template T>
d) template < class T, class U>
Whatsapp 0328-4090195
Mid-Term CS304(Object Oriented Programming) Page 31 of 50
...
}
Select the best option,
a) Fred a[10]; calls the default constructor 09 times Fred* p = new Fred[10]; calls the default
constructor 10 times
b) Produce an error
c) Fred a[10]; calls the default constructor 11 times Fred* p = new Fred[10]; calls the
default constructor 11 times
d) Fred a[10]; calls the default constructor 10 times Fred* p = new Fred[10]; calls the default
constructor 10 times
114. When a variable is define as static in a class then all object of this class,
a) Have different copies of this variable
b) Have same copy of this variable
c) Can not access this variable
d) None of given
115. The life of sub object is dependent on the life of master class in _____________.
a) Separation
b) Composition
c) Aggregation
d) None of the given
116. In Private __________ only member functions and friend classes or functions of a
derived class can convert pointer or reference of derived object to that of parent object
a) specialization
Whatsapp 0328-4090195
Mid-Term CS304(Object Oriented Programming) Page 32 of 50
b) inheritance
c) abstraction
d) composition
120. Identify the correct way of declaring an object of user defined template class A for char
type members?
a) A< char > obj;
b) <char>A obj;
c) A obj<char>;
Whatsapp 0328-4090195
Mid-Term CS304(Object Oriented Programming) Page 33 of 50
d) Obj <char> A;
Whatsapp 0328-4090195
Mid-Term CS304(Object Oriented Programming) Page 34 of 50
what will happen?
a) The following statement will add an element to the start (the back) of evec and will
initialize it with the value 21.
b) The following statement will add an element to the center of evec and will reinitialize it
with the value 21.
c) The following statement will delete an element to the end (the back) of evec and will
reinitialize it with the value 21.
d) The following statement will add an element to the end (the back) of evec and initialize it
with the value 21.
126. Default constructor is such constructor which either has no _________or if it has some
parameters these have __________ values
a) Parameter, temporary
b) Null, Parameter
c) Parameter, default
d) none of the given
127. Public methods of base class can --------- be accessed in its derived class
a) directly
b) indirectly
c) simultaneously
Whatsapp 0328-4090195
Mid-Term CS304(Object Oriented Programming) Page 35 of 50
d) none of the given
128. The type that is used to declare a reference or pointer is called its ---------
a) default type
b) static type
c) abstract type
d) reference type
131. Graphical representation of the classes and objects is called object model it
shows______
a) Class Name only
b) Class Name and attributes
c) Relationships of the objects and classes
Whatsapp 0328-4090195
Mid-Term CS304(Object Oriented Programming) Page 36 of 50
d) all of the given
133. Outside world can access only __________ members of a class using its object.
a) Public
b) Private
c) Protected
d) No member is accessible
134. Consider the code below, class class1{ private: int i; }; class class2 : protected class1 {
};
Then int member i of class1 is ______ in class2,
a) public
b) protected
c) private
d) none of the given options
135. Consider the code below, class class1{ protected: int i; }; class class2 : public class1 { };
Then int member i of class1 is ______ in class2,
a) public
b) protected
Whatsapp 0328-4090195
Mid-Term CS304(Object Oriented Programming) Page 37 of 50
c) private
d) none of the given options
136. ___________ Binding means that target function for a call is selected at run time
a) Automatic
b) Dynamic
c) Static
d) Dramatic
137. In Protected Inheritance the public members of base class become __________ in
derived class.
a) Public
b) Private
c) Protected
d) None of the given options.
138. Suppose both derive and base classes have compiler generated copy constructors then
derived class copy constructor will call base class __________,
a) Compiler generated default constructor
b) Compiler generated copy constructor
c) Both of these options are correct
d) None of these options are correct
139. Consider the code below, class c1{ }; class c2 : public c1 { }; class c3 : public c2 { };
Then c3 is,
Whatsapp 0328-4090195
Mid-Term CS304(Object Oriented Programming) Page 38 of 50
a) Direct base class of c1
b) Direct child class of c1
c) Direct base class of c2
d) Direct child class of c2
143. When the base class and the derived class have a member function with the same name,
you must be more specific which function you want to call (using ___________).
Whatsapp 0328-4090195
Mid-Term CS304(Object Oriented Programming) Page 39 of 50
a) scope resolution operator
b) dot operator
c) null operator
d) Operator overloading
144. Two important STL associative containers are _______ and _______.
a) set, map
b) sequence, mapping
c) setmet, multipule
d) sit, mat
145. The mechanism of selecting function at run time according to the nature of calling
object is called,
a) late binding
b) static binding
c) virtual binding
d) None of the given options
Whatsapp 0328-4090195
Mid-Term CS304(Object Oriented Programming) Page 40 of 50
a) 0
b) 0.0
c) 1
d) Null
148. Which one of the following functions returns the total number of elements in a vector.
a) length();
b) size();
c) ele();
d) veclen();
150. All of the given choices this pointer does not pass implicitly to __________ functions.
a) Static Member
b) Non-Static Member
c) Instance Number
d) None of the given
Whatsapp 0328-4090195
Mid-Term CS304(Object Oriented Programming) Page 41 of 50
b) User defined copy constructor, shallow copy is implement
c) Default copy constructor, deep copy is implemented
d) User defined copy constructor, deep copy is implement
153. Suppose you have been given the following design, _____A person has a name, age,
address and _____. You are designing a class to represent a type of person called a patient.
This kind of person may be given a diagnosis, have a spouse and may be alive. Given that
the person class has already been created, what of the following would be appropriate to
include when you design the patient class?
a) registration date and diagnosis
b) age and —–
c) and diagnosis
d) diagnosis and age
155. Which of the following is the correct syntax of declaring static variable ‘count’ of type
int?
Whatsapp 0328-4090195
Mid-Term CS304(Object Oriented Programming) Page 42 of 50
Static int count
156. Which of the following will happen when a constant function tries to change the value
of data members of the class?
Complex time error will occur
159. In Object Oriented programming objects communicate with each other through
Messages
Whatsapp 0328-4090195
Mid-Term CS304(Object Oriented Programming) Page 43 of 50
Vehicle
161. Suppose test is a class, void show() is its public member function. Which of the following
is
correct call of
Show() function using Test pointer
ptr?
Ptr->show()
Whatsapp 0328-4090195
Mid-Term CS304(Object Oriented Programming) Page 44 of 50
170. Suppose person is a class which of the following statement defines an object of class
person?
Create person object
Whatsapp 0328-4090195
Mid-Term CS304(Object Oriented Programming) Page 45 of 50
171. If you have three classes in a C++ program A, B, and C where class A inherits from
class B, then class _______contains all the characteristics of class_______
A,C
176. What is the general syntax of overloading Unary Operator as member function of the
class?
TYPE & operator OP ();
Whatsapp 0328-4090195
Mid-Term CS304(Object Oriented Programming) Page 46 of 50
177. Which of the following function declaration is correct to overload the + operator as
member function in complex class?
Complex operator +(const Complex &rhs);
180. In case when we define the function outside the class then we must use the keyword
________To make the function inline.
Inline
181. Which of the following classes are used by Amphibious vehicle to inherit
characteristics?
Both Land & Water Vehicle
182. In polymorphism, messages can be interpreted in different ways depending upon the
Whatsapp 0328-4090195
Mid-Term CS304(Object Oriented Programming) Page 47 of 50
class.
Receiver
Whatsapp 0328-4090195
Mid-Term CS304(Object Oriented Programming) Page 48 of 50
Generic programming
189. In statement template <class T,class U ,int |=5> the non-parameter is________.
Class U
192. Which of the following is the correct syntax of declaring static variable “count” of type
int?
Static int count;
193. In case of private inheritance, private members of base class will be _______in derived
Class.
Hidden
Whatsapp 0328-4090195
Mid-Term CS304(Object Oriented Programming) Page 49 of 50
194. Suppose we have defined derived class copy constructor but have not defined base class
Copy constructor then compiler will,
Use base class default constructor
196. The parameters given in template definition other than those used for mentoring
templates types are called________
Non-type parameters
199. What will the value of variables a, b, and c after instantiating an object of above class?
Junk Value, 5, Junk value
Whatsapp 0328-4090195
Mid-Term CS304(Object Oriented Programming) Page 50 of 50
200. What is the output of the following code?Int main()
{intconst x = 10; cout<< ++x; return 0;}
11
201. If there is a pointer p to objects of a base class , and it contains the address of an object
of a derived Class, and both classes contain a virtual member function, ding(), then the
statement p->ding(); will cause the version of ding() in the class to be executed.
Derived
202. In C++ by default access of classes is.
Private
Best of Luck
For Free help, more Mid/Final term Files and for Exam Preparation You Can
Join:
https://chat.whatsapp.com/F094bNv5NKYD23JUH7AAY8
Whatsapp 0328-4090195