Computer Science, asked by TRB, 9 months ago

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​

Answers

Answered by UmemaTazmeen
4

Answer:

The correct answer is (c) .

Explanation:

HOPE IT HELPS U!!!

Answered by SmritiSami
0

The role of a constructor in classes is to initialize the data members of an object when it is created. (Option C)

  • A constructor is a particular member function of a class that is called whenever new objects of that class are created.
  • A function Object will be named the same as the class, and it will have no return type, not even void.
  • Constructors have the same name as the class or struct, and they often initialize the new object's data members.
  • A basic function Object is used to establish a Taxi class in the following example.
  • To avoid errors/segmentation issues, constructors are used in classes to initialize data members. The copy function Object allows the user to initialize an object using the values of another object rather than giving the same set of values again.
Similar questions