OOPs MCQ
OOPS is Object-Oriented Programming. It is an approach to developing software programming. It was introduced to overcome flaws in the procedural approach to programmings such as reusability and maintainability. Object-oriented programming or OOPS is a methodology of designing an application using classes and objects.
The fundamental idea behind object-oriented language is to combine into a single unit with both data and functions.
The data and functions that operate on that data such as a unit are called an object.
A class is a blueprint from which objects are created. A class describes the state or behavior of an object. A class can have attributes and methods:
- Attributes: An Attribute is a public variable inside the class/object. For example, Length is an attribute of int data type. In other words, **class attributes** are the variable within a class. You can access attributes by creating an object of a class and by using dot syntax(.).
- Methods: A method is a group/block of code that takes input from the user, process it, and provides the output. The method runs only when it is called.
Object:
An object is an instance of a class. It contains an address and takes up memory space. Objects have states and behavior defined as per their template definition.
Instance member variable: Attributes, data members, field, properties.
Instance member functions: Methods, procedures, actions, operations, services.
Features of OOPS
There are primarily four pillars of OOPS:
- Data abstraction :
- Data hiding: It hides implementation details while just presenting the features to the outside world
- Reduces code complexity
- Hides details and exposes the essential parts.
- Inheritance: Reusability
- Mechanism of deriving a new class from an existing class.
- Types:
- Single level
- Multi-level
- Multiple
- Hierarchical
- Hybrid
- Polymorphism: Object to take many forms
- Types:
- Compile-time polymorphism
- Run time polymorphism
- Types:
- Encapsulation :
- Hiding the data for purpose of protection.
- Writing data and functions into a single unit.
OOPs MCQs
What is an object in c++?
It is a function of class
It is an instance of the class
It is the data type of class
It is part of the syntax of class.
In which of the following is memory allocated for the objects?
RAM
ROM
Cache
HDD
On what basis is it determined, when a variable comes into existence in memory?
Data type
Storage class
Scope
All of the above
Select the following which shows the correct constructor.
()class_name
-class_name
class_name()
~class_name()
To access data members of a class, which of the following is used?
Dot operator
Arrow operator
Dot or arrow operator, as required
Dot, arrow, or direct call
Total access specifiers in OOPS for C++ are?
1
2
3
4
Total instances of an abstract class that can be created?
0
1
4
8
Total types of constructors in C++ are?
1
2
3
4
Total types of polymorphism in C++ are?
1
2
3
4
Under which pillar of OOPS do base class and derived class relationships come?
Polymorphism
Inheritance
Encapsulation
Abstraction
Virtual function should be ________.
public
Private
protected
default
Virtual functions should be defined in?
Derived class
Base class
Both base and derived class
None
What are the total catch blocks that can be used using a single Try block?
1
2
According to needs
Maximum 256
Identify the scope resolution operator.
:
::
?:
None
What is cout?
Operator
Object
Function
Macro
What is the implicit return type of constructor?
No return type
A class object in which it is defined.
void
None
What is the number of parameters that a default constructor requires?
0
1
2
3
What type of inheritance does single-level inheritance support?
Compile-time
Runtime inheritance
Multiple inheritances
Language independent
When is the object created with a new keyword?
At run time
At compile time
Depends on the code
None
Which of the following functions can be inherited from the base class?
Constructor
Destructor
Static
None
Which of the following is not a type of inheritance?
Multiple
Multilevel
Distributed
Hierarchical
Which of the following is not an oops concept?
Inheritance
Compilation
Polymorphism
Encapsulation
Which type of inheritance is implemented in the following code below?
Single inheritance
Multilevel inheritance
Hybrid inheritance
Multiple inheritances
Who developed object-oriented programming?
Dennis Ritchie
Charles Babbage
Alan Kay
Andrea Ferro
Why is a virtual function mainly used to achieve?
Function code polymorphism
Interpreter polymorphism
Compile-time polymorphism
Runtime polymorphism
Why is reusability a desirable feature?
Reduces compilation time
Decreases testing time
Lowers maintenance cost
None
Choose whether True or False: The constructor function can be constant.
True
False
Depends on implementation
None
Another name of the generic class is?
Template class
Final class
Abstract class
Efficient code
By default, fields in a structure of a C program is?
public
Private
protected
None
Choose the incorrect option below which is not a type of constructor.
Copy constructor
Friend constructor
Parameterized constructor
Default constructor
Choose the option below for which instance of the class cannot be created.
Anonymous class
Parent class
Nested class
Abstract class
Choose the option below which can show polymorphism.
Overloading ||
Overloading <<
Overloading &&
Overloading +=
Choose the option below which describes the overloading of functions.
Ad-hoc polymorphism
Virtual polymorphism
Pseudo polymorphism
Transient polymorphism
Choose the option below which is not a member of the class.
Friend function
Static function
Virtual function
Const function
Choose the option below which is shown by function overriding
Abstraction
Encapsulation
Polymorphism
Inheritance
Choose the option below which is used to free the memory allocated for an object in C++.
Free()
unallocate()
delete
collect
Choose the option below which is used to implement late binding.
Friend function
Static function
Virtual function
Const function
Choose the option below which overloads using the friend function.
()
->
*
=
Choose whether True or False: Object cannot be passed as a function.
True
False
Depends on implementation
None
Another name of overloading is?
Pseudo polymorphism
Transient polymorphism
Virtual polymorphism
Ad-hoc polymorphism
Data members and member functions of a class are private. default. True or False?
True
False
Depends on code
None
Dynamic memory allocation can be done using?
calloc()
malloc()
Both (a) and (b)
create()
How do encapsulation and abstraction differ?
Hiding and binding
Binding and hiding
Hiding and hiding
None
Identify the abstract data type among the following.
double
int
class
string
Identify the feature using which, one object can interact with another object.
Message passing
Message reading
Data binding
Data transfer
Identify the feature which can be implemented using encapsulation.
Abstraction
Encapsulation
Polymorphism
Inheritance
Identify the feature, which is used to reduce the use of nested classes.
Binding
Inheritance
Encapsulation
Abstraction
Identify the incorrect constructor type.
Friend constructor
Default constructor
Parameterized constructor
Copy constructor
Identify the operators which cannot be overloaded.
?:
.(dot operator)
>>
Both A and B
Identify the option below which cannot be used with the term “virtual”.
constructor
destructor
class
Member function
Identify the option below which is not a property of the object.
Names
Attributes
Identity
Properties
Identify the pure object-oriented programming language among the following.
C++
SmallTalk
Java
Python