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
  • Encapsulation :
    • Hiding the data for purpose of protection.
    • Writing data and functions into a single unit.

OOPs MCQs

1. 

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.

2. 

In which of the following is memory allocated for the objects?

RAM

ROM

Cache

HDD

3. 

On what basis is it determined, when a variable comes into existence in memory?

Data type

Storage class

Scope

All of the above

4. 

Select the following which shows the correct constructor.

()class_name

-class_name

class_name()

~class_name()

5. 

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

6. 

Total access specifiers in OOPS for C++ are?

1

2

3

4

7. 

Total instances of an abstract class that can be created?

0

1

4

8

8. 

Total types of constructors in C++ are?

1

2

3

4

9. 

Total types of polymorphism in C++ are?

1

2

3

4

10. 

Under which pillar of OOPS do base class and derived class relationships come?

Polymorphism

Inheritance

Encapsulation

Abstraction

11. 

Virtual function should be ________.

public

Private

protected

default

12. 

Virtual functions should be defined in?

Derived class

Base class

Both base and derived class

None

13. 

What are the total catch blocks that can be used using a single Try block?

1

2

According to needs

Maximum 256

14. 

Identify the scope resolution operator.

:

::

?:

None

15. 

What is cout?

Operator

Object

Function

Macro

16. 

What is the implicit return type of constructor?

No return type

A class object in which it is defined.

void

None

17. 

What is the number of parameters that a default constructor requires?

0

1

2

3

18. 

What type of inheritance does single-level inheritance support?

Compile-time

Runtime inheritance

Multiple inheritances

Language independent

19. 

When is the object created with a new keyword?

At run time

At compile time

Depends on the code

None

20. 

Which of the following functions can be inherited from the base class?

Constructor

Destructor

Static

None

21. 

Which of the following is not a type of inheritance?

Multiple

Multilevel

Distributed

Hierarchical

22. 

Which of the following is not an oops concept?

Inheritance

Compilation

Polymorphism

Encapsulation

23. 

Which type of inheritance is implemented in the following code below?

Single inheritance

Multilevel inheritance

Hybrid inheritance

Multiple inheritances

24. 

Who developed object-oriented programming?

Dennis Ritchie

Charles Babbage

Alan Kay

Andrea Ferro

25. 

Why is a virtual function mainly used to achieve?

Function code polymorphism

Interpreter polymorphism

Compile-time polymorphism

Runtime polymorphism

26. 

Why is reusability a desirable feature?

Reduces compilation time

Decreases testing time

Lowers maintenance cost

None

27. 

Choose whether True or False: The constructor function can be constant.

True

False

Depends on implementation

None

28. 

Another name of the generic class is?

Template class

Final class

Abstract class

Efficient code

29. 

By default, fields in a structure of a C program is?

public

Private

protected

None

30. 

Choose the incorrect option below which is not a type of constructor.

Copy constructor

Friend constructor

Parameterized constructor

Default constructor

31. 

Choose the option below for which instance of the class cannot be created.

Anonymous class

Parent class

Nested class

Abstract class

32. 

Choose the option below which can show polymorphism.

Overloading ||

Overloading <<

Overloading &&

Overloading +=

33. 

Choose the option below which describes the overloading of functions.

Ad-hoc polymorphism

Virtual polymorphism

Pseudo polymorphism

Transient polymorphism

34. 

Choose the option below which is not a member of the class.

Friend function

Static function

Virtual function

Const function

35. 

Choose the option below which is shown by function overriding

Abstraction

Encapsulation

Polymorphism

Inheritance

36. 

Choose the option below which is used to free the memory allocated for an object in C++.

Free()

unallocate()

delete

collect

37. 

Choose the option below which is used to implement late binding.

Friend function

Static function

Virtual function

Const function

38. 

Choose the option below which overloads using the friend function.

()

->

*

=

39. 

Choose whether True or False: Object cannot be passed as a function.

True

False

Depends on implementation

None

40. 

Another name of overloading is?

Pseudo polymorphism

Transient polymorphism

Virtual polymorphism

Ad-hoc polymorphism

41. 

Data members and member functions of a class are private. default. True or False?

True

False

Depends on code

None

42. 

Dynamic memory allocation can be done using?

calloc()

malloc()

Both (a) and (b)

create()

43. 

How do encapsulation and abstraction differ?

Hiding and binding

Binding and hiding

Hiding and hiding

None

44. 

Identify the abstract data type among the following.

double

int

class

string

45. 

Identify the feature using which, one object can interact with another object.

Message passing

Message reading

Data binding

Data transfer

46. 

Identify the feature which can be implemented using encapsulation.

Abstraction

Encapsulation

Polymorphism

Inheritance

47. 

Identify the feature, which is used to reduce the use of nested classes.

Binding

Inheritance

Encapsulation

Abstraction

48. 

Identify the incorrect constructor type.

Friend constructor

Default constructor

Parameterized constructor

Copy constructor

49. 

Identify the operators which cannot be overloaded.

?:

.(dot operator)

>>

Both A and B

50. 

Identify the option below which cannot be used with the term “virtual”.

constructor

destructor

class

Member function

51. 

Identify the option below which is not a property of the object.

Names

Attributes

Identity

Properties

52. 

Identify the pure object-oriented programming language among the following.

C++

SmallTalk

Java

Python

Get Placed at Top Product Companies with Scaler Hide