Subject

    Computer Science

    Topic

    Computer Hardware

    In object-oriented programming, a 'constructor' is a special method that is automatically called when:

    a)
    An object is destroyed or deallocated.
    b)
    An object is created from a class.
    c)
    A private member of the class is accessed.
    d)
    The program starts execution.

    Explanation

    The constructor's primary job is to initialize the newly created object. It sets the initial values for the object's instance variables (fields) and performs any other setup necessary for the object to be in a valid state. The method often has the same name as the class itself.

    Find Tutors

    View all Tutors