In the context of object-oriented programming, which of the following options…

2025

In the context of object-oriented programming, which of the following options accurately describes a constructor in a class?

  1. A.

    A method that returns a value and must be explicitly called to initialize variables

  2. B.

    A predefined static block executed before any method or field of the class

  3. C.

    A member function that shares the class name and is automatically invoked during object creation

  4. D.

    A special function used to allocate memory dynamically for class instances

Attempted by 104 students.

Show answer & explanation

Correct answer: C

A constructor is a special method used to initialize objects when they are created.

Explore the full course: Rssb Senior Computer Instructor