Professional Documents
Culture Documents
cs304 Quiz 2 by Smile?
cs304 Quiz 2 by Smile?
Suppose derived class is inherited from base class. What happens when a derived class object
is created?
The constructor of base class is executed before the constructor of derived class.
Suppose str1, str2 and str3 are objects of class String. Choose appropriate declaration of
overloaded assignment operator for the following statement to work correctly.
<<
Choose correct declaration of overloaded inequality (!=) operator for class String as non-
member friend function.
Composition
Student() {//...
The sub-object’s life is not dependent on the life of master class in ___________.
Aggregation
Inline
Deconstruct is a function which has the same name as that of class but starts with a—– sign
Static Member
Eat
In Object Oriented programming, objects communicate with each other through ________
Messages
Initialize
Hidden
Extension
Suppose a class does not have any constructor. What will happen when an object of this class is
created?
Inline
Extension
& symbol
Parent
Which of the following function declaration is correct to overload the + operator as member function in
Complex class?
What is the general syntax of overloading Unary Operator as member function of the class?
Composition
Suppose student is a class, which of the following constructor with one parameter for class student?
Student()
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
Suppose person is a class which of the following statement defines an object of class person?
Create person object
Which of the following statement is NOT true about static variable of a class?
Suppose str1, str2, and str3 are objects of class string. Choose appropriate declaration of overloaded
assignment operator for the following statement to work correctly.
String& operator=(const String &)
The process of extracting common characteristics from two or more classes and combining them into a
generalized superclass is called ___
Generalization
This car is composed of wheels. What is the relationship between car and wheels?
Composition
In ____ base class can be replaced by the derived class.
Extension
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()
Which of the following features of OOP is used to deal with only relevant details?
Abstraction
In C++ the subscript operator must be overloaded as a ___ of the class, with one parameter of ___ type.
Member function, int
If you do not initialize static variable of int type then it is automatically initialized with ____
0
Choose the correct statement
All of the given options
In Object Oriented programming objects communicate with each other through ____
Messages
Which of the following allows to reuse characteristics of more than one parent class?
Multiple Inheritance
Which of the following features of OOP is used to deal with only relevant details?
Abstraction
The overloaded ‘-‘ operator for complex class will be called with reference to ___ in the following
statement
Complex C3 = C1 – C2
Complex
Static data member is declared __
Inside the class
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
Mermaid is an example of
Multiple inheritance
Which of the following is the correct syntax of declaring static variable ‘count’ of type int?
static int count
Which of the following operators operate on one operand?
Unary Operators
In case when we define the function outside the class then we must use the keyword ___ to make
function inline.
Inline
The Specialization pattern after the name says that this specialization is to be
used for every___.
Select correct option:
data types
meta types
virtual types
pointers type
Consider the code below, class class1{ protected: void func1(); }; class class2
: public class1 { }; Function func1 of class1 is ____ in class2,
Select correct option:
public
protected
private
none of the given options
Consider the code below, class class1{ protected: int i; }; class class2 :
protected class1 { }; Then int member i of class1 is ____ in class2,
Select correct option:
public
protected
private
none of the given options
Consider the code below, class class1{ private: void func1(); }; class class2 :
private class1 { }; Function func1 of class1 is ____ in class2,
Select correct option:
public
protected
private
none of the given options
The Specialization pattern after the name says that this specialization is to be used for
every___.
Select correct option:
data types
meta types
virtual types
pointers type
c++ dynamic binding and polymorphism will be achieved when member function will
be __.
Select correct option:
private
public
virtual
inline
Consider the code below, class class1{ protected: void func1(); }; class class2 : public
class1 { }; Function func1 of class1 is ____ in class2,
Select correct option:
public
protected
private
none of the given options
Consider the code below, class class1{ protected: int i; }; class class2 : protected class1
{ }; Then int member i of class1 is ____ in class2,
Select correct option:
public
protected
private
none of the given options
Consider the code below, class class1{ private: void func1(); }; class class2 : private
class1 { }; Function func1 of class1 is ____ in class2,
Select correct option:
public
protected
private
none of the given options
Consider the code below, class class1{ private: int i; }; class class2 : private class1 { };
Then int member i of class1 is ____ in class2,
Select correct option:
public
protected
private
none of the given options
Derived class can inherit from public base class as well as private and protected base
classes
Select correct option:
True
False
Two functions with same names, parameters and return type can exist in,
Select correct option:
Function overloading
Function overriding
Operator overloading
None of these options
Consider the code below, class class1{ private: int i; }; class class2 : public class1 { };
Then int member i of class1 is ____ in class2,
Select correct option:
public
protected
private
none of the given options
hello
A class hierarchy
Select correct option:
shows the same relationships as an organization chart.
describes “has a” relationships.
describes “is a kind of” relationships.
shows the same relationships as a family tree.
Consider the code below, class class1{ public: int i; }; class class2 : public class1 { };
Then int member i of class1 is ____ in class2,
Select correct option:
public
protected
private
none of the given options
Consider the code below, class c1{ }; class c2 : public c1 { }; class c3 : public c2 { };
Then c1 is,
Select correct option:
Direct base class of c3
Direct child class of c3
Direct base class of c2
Direct child class of c2
This specialization can then be used as the common implimentation for all Vectors of
pointers.
This spcialization can then be used as the all type implimentation for one type classes.
This specialization can then be used double type pointers.
This specialization should be used for Vectors of all type int types.
Consider the code below, class class1{ public: int i; }; class class2 : protected class1 { };
Then int member i of class1 is ____ in class2,
Select correct option:
public
protected
private
none of the given options
Consider the code below, class class1{ private: void func1(); }; class class2 : public
class1 { }; Function func1 of class1 is ____ in class2,
Select correct option:
public
protected
private
none of the given options
_________ Binding means that target function for a call is selected at run time
Select correct option:
Automatic
Dynamic
Static
Dramatic
When we create objects, then space is allocated to:
Member function
Access specifier
Data member
None of given
True
False
Which of the following features of OOP is used to deal with only relevant details?
Abstraction
Information hiding
Object
____________ Binding means that targets function for a call is selected at compile time.
Static
Dynamic
Automatic
None of given
A Class hierarchy
In C++, we declare a function virtual by preceding the function header with keyword
“Inline”
True
False
Generic Template
Partial Specification
Complete Specification
Ordinary function
Derived class can inherit from public base class as well as private and protected base
classes
True
False
Which line will produce error. Class phone: Private Transmit, private Receiver { } 1.int
main () 2. { 3.phone obj; 4.Tranmit*obj1 = &obj; 5.Received obj2 = &obj; 6.}
Structure programming
Procedural programming
Generic programming
None of the given
Vector
Class
Template
Type*
Friends are used exactly the same for template and non-template classes.
True
False
A function template must have a parameter
True
False
None of these.
None of given
A class D can be derived from a class C, which is derived froma class B, which is
derived from a class A
True
False
Adding a derived class to a base class requires fundamental changes to the base class.
True
False
A Class or class template can have member ___________ that are themselves
templates.
Variable
Function
Objects
None of given
Private Inheritance
Base
Derived
Virtual
Implemented
Sender of the message does not need to know the exact class of receiver in________.
Abstraction
Polymorphism
Inheritance
CS304 Object Oriented Programming 1. Select correct line of code for inheritance
relationship between “Gender” class and “Male” class. “Gender” is parent class
while “Male” is child class.
class Male: public Gender
class Gender: public Male
class Male:: public Gender
class Gender:: public Male
CS304 Object Oriented Programming 3.Select correct line of code for inheritance
relationship between “Person” class and “Supervisor” class. “Person” is parent
class while “Supervisor” is child class.
class Supervisor: public Person
class Person: public Supervisor
class Supervisor:: public Person
class Person:: public Supervisor
CS304 Object Oriented Programming 5. Select correct line of code for inheritance
relationship between “Keys” class and “SpecialKeys” class. “Person” is parent
class while “SpecialKeys” is child class.
class SpecialKeys: public Keys
class Keys: public SpecialKeys
class SpecialKeys:: public Keys
class Keys:: public SpecialKeys
CS304 Object Oriented Programming 10. Let Suppose a class Student with
objects std1, std2, and std3. For the statement std3 = std1 - std2 to work
correctly, if the overloaded - operator must
take two arguments.
None of the given choices
take single argument
take three arguments
CS304 Object Oriented Programming 12. Which of the following operator doesn't
take any argument if overloaded?
/
-
+
None of the given choices
CS304 Object Oriented Programming 13. “A fan has wings”. Which type of
relationship exists between fan and wings?
Aggregation
Association
Composition
Inheritance
CS304 Object Oriented Programming 15. Select correct line of code for
inheritance relationship between “Nationality” class and “Citizen” class.
“Nationality” is parent class while “Citizen” is child class.
class Citizen: public Nationality
class Nationality: public Citizen
class Citizen:: public Nationality
class Nationality:: public Citizen
1. Public
2. Private
3. Protected
4. All of the given
2. Which of the following is NOT casting operator in C++
standard?
1. static_cast
2. var_cast
3. dynamic_cast
4. reinterpret_cast
3. Which of the following types of Inheritance is used to model
"Implemented in terms of" relationship?
1. Public
2. Private
3. Protected
4. Confidential
4. In case of protected inheritance, public members of base class
will be ________ in derived class?
1. private
2. public
3. protected
4. hidden
5. In C++ by default access of classes is ________.
1. Private
2. Protected
3. Public
4. None of the given
6. 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.
1. base
2. derived
3. virtual
4. implemented
7. Suppose we have defined derived class copy constructor but
have not defined base class copy constructor then compiler
will,
1. private
2. public
3. protected
4. hidden
9. A template argument is preceded by the keyword ________.
1. vector
2. class
3. template
4. type*
10. ________ Binding means that target function for a call is
selected at compile time.
1. Static
2. Dynamic
3. Automatic
4. None of the given
11. In case of public inheritance, protected members of base
class will be ________ in derived class.
1. private
2. public
3. Protected
4. hidden
12. A template provides a convenient way to make a family of
1. Single class
2. Single derived class
3. Single base class
4. Derived and base class
14. Which of the following is TRUE.
1. Public inheritance
2. Protected inheritance
3. Private inheritance
4. None of the given
16. In Protected Inheritance the public members of base class
become ________ in derived class.
1. Public
2. Private
3. Protected
4. None of the given
17. In resolution order compiler search firstly ________.
1. Generic Template
2. Partial Specialization
3. Complete Specialization
4. Ordinary function
18. Compiler generated copy constructor performs ________.
1. Shallow copy
2. Deep copy
3. Both Shallow and Deep copy
4. None of the given
19. A pure virtual function is a virtual function that
1. causes its class to be abstract.
2. returns nothing.
3. is used in a derived class.
4. takes no arguments.
20. Methodologies to the development of reusable software
relate to ________.
1. Structure programming
2. procedural programming
3. generic programming
4. None of the given
21. In C++ generic programming is done using ________.
1. Procedures
2. Packages
3. Templates
4. None of the given
22. Consider the code below,
class class1{
private:
void func1();
};
class class2 : private class1 {
};
Function func1 of class1 is ________ in class2.
1. public
2. protected
3. private
4. None of the given
23. When derived class has user defined assignment operator.
1. public
2. protected
3. private
4. None of the given
26. Consider the code below,
class class1{
protected:
int i;
};
class class2 : private class1 {
};
1. public
2. protected
3. private
4. None of the given
27. Static casting is,
1. Implicit way of calling base class functions from derived class
2. Explicit way of calling base class functions from derived class
3. Both of the given
4. None of the given
28. How many objects of a given class may be constructed in
an application?
1. Restriction
2. Extension
3. Dependency
4. Subtyping
30. How can we differentiate between constructors and
destructors?
1. 1
2. 2
3. 3
4. 4
32. Which of the following is True about Destructor?
1. It is used to free memory that is allocated through dynamic
allocation.
2. Free memory allocated using new operator by over self in
destructor.
3. It is used to perform house keeping operations.
4. All of the given
33. How many objects are involved in the N-ary association?
1. More than 1
2. More than 2
3. More than 3
4. More than 4
34. Which of the following can be the behavior of an object
"Usman"?
1. Name
2. Age
3. Address
4. Eat
35. In C++, Composition is a relationship between ________
and ________ objects.
1. Parent, child
2. Base, derived
3. Whole, part
4. All of the given
36. 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 ________.
1. B, A
2. A, B
3. A, C
4. B, C
37. In case when we define the function outside the class then
we must use the keyword ________ to make the function
inline.
1. requestin
2. inlineout
3. inline
4. defineinline
38. Mermaid is an example of:
1. Single inheritance
2. Polymorphism
3. Specialization
4. Multiple Inheritance
39. Assignment operators are:
1. Left associative
2. Right associative
3. Left and right associative
4. Non associative
40. Generalization is ________ approach.
1. Bottom-up
2. Top-bottom
3. Right-Left
4. Left-Right
41. The ________ tells the compiler what task the function will
be performing.
1. Function declaration
2. Function calling
3. Function definition
4. None of the given
42. Suppose str1, str2 and str3 are objects of class String.
Choose appropriate declaration of overloaded assignment
operator for the following statement to work correctly.
1. void operator =(const String &);
2. String& operator =(const String &);
3. String& overload =(const String &);
4. void op =(const String &);
43. In operator overloading, which of the following operator
takes one or no argument.
1. ++
2. *
3. %
4. <<
44. Class is blueprint of ________.
1. Interface
2. Class
3. Objects
4. Model
45. Polymorphism makes the system:
1. reusable
2. flexible
3. faster
4. All of the given
46. If class B inherits from class A then it contains all
characteristics of ________.
1. Class B
2. Class A
3. No inheritance
4. None of the given
47. What is meant by multiple inheritance?
1. Equality Operator: ==
2. Inequality Operator: !=
3. Function Operator: ()
4. Stream Extraction Operator: >>
49. Insertion operator is ________ associative.
1. Right to Left
2. Left to Right
3. Left to Left
4. Right to Right
50. In expression c1*c2+c3-c4 which of the following will be
executed in first order?
1. c1*c2
2. c2+c3
3. c3-c4
4. c1-c4
51. Suppose for a class String, assignment operator is
overloaded with following declaration.
void operator =(const String &);
What will happen when we will write following statement in
main()?
str1 = str2 = str3;
Where, str1, str2 and str3 are objects of class String.
"Vehicle class is base class. Bus, Car, and Truck are derived
classes"
1. Vehicle
2. Bus
3. Car
4. Truck
53. Which of the following operators operate on one operand?
1. Binary Operators
2. Unary Operators
3. Ternary Operator
4. All of the given
54. Subtyping means that derived class is behaviorally
________ with the base class.
1. Same
2. Compatible
3. Different
4. Incompatible
55. In ________, Base class can't always be replaced by the
derived class.
1. Aggregation
2. Inheritance
3. Specialization
4. Extension
56. The overloaded '-' operator for Complex class will be called
with reference to ________ in the following statement
Complex C3 = C1 - C2;
1. Complex
2. C1
3. C2
4. C3
57. What is a class?
1. base
2. derived
3. sender
4. receiver
59. Suppose there is an object of type Person, which of the
following can be considered as one of its attributes?
1. Name
2. Eat
3. Work
4. Sleep
60. Which of the following is True about class?
1. const
2. static
3. explicit
4. virtual
62. Choose correct declaration of overloaded stream insertion
operator for class String as non-member friend function.
1. Land Vehicle
2. Water Vehicle
3. Both Land & Water Vehicle
4. None of the given
64. Constructors have ________ return type.
1. int
2. char
3. void
4. no
65. The other name of specialization is ________.
1. Restriction
2. Extension
3. Dependency
4. Subtyping
66. ________ is represented by a line with an unfilled diamond
head towards the container.
1. Inheritance
2. Association
3. Aggregation
4. Composition
67. ________ remain in memory even when all objects of a
class have been destroyed.
1. Static Variables
2. Instance Variables
3. Primitive Variables
4. None of the given
68. Static Data Member is declared ________.
1. Loosely
2. Openly
3. Closely
4. Not
70. In which of the following OOP paradigm objects cannot
exist independently?
1. Polymorphism
2. Inheritance
3. Aggregation
4. Composition
71. In order to make any function constant, keyword const is
placed at the ________ of the parameter list.
1. Beginning
2. Middle
3. End
4. None of the given
72. "Student registers Course and Teacher teaches the
Course." is an example of:
1. Binary Association
2. Two way Association
3. Ternary Association
4. N-ary Association
73. Which of the following can be the attribute of an object
"Ali"?
1. Eat
2. Walk
3. Sleep
4. Address
74. Consider the statement "room has chair" Which of the
following type of association exists between room and chair?
1. Inheritance
2. Composition
3. There is no association
4. Aggregation
75. We can access a private static variable through:
1. User perspective
2. Owner perspective
3. Random information
4. All information
77. Which of the following concept is more close to
encapsulation?
1. Exception Handling
2. Inheritance
3. Polymorphism
4. Information Hiding
78. How the information hidden within an object can be
accessed?
1. Operator Associativity
2. Operator Precedence
3. Arity of Operators
4. None of the given
80. Which of the following is the correct syntax of declaring
static variable "count" of type int?
int main()
{
int const x = 10;
cout << ++x;
return 0;
}
1. 10
2. 11
3. Error
4. None of the given
83. Which of the following statements best describes the
Constructor?
1. Constructor is used to modify constant data members of the
class.
2. Constructor is used to delete the objects of a class.
3. Constructor is used to initialize the data members of a class.
4. All of the given
84. Consider the following code segment:
class test
{
int a;
int b;
int c;
public:
test():b(5).c(a).a(b){}
}
1. 5, 5, 5
2. 5, Junk value, 5
3. Junk value, 5, Junk value
4. Junk value, 5, 5
85. Which of the following is a strong relationship?
1. Inheritance
2. Composition
3. Association
4. Polymorphism