If a constructor 'Date' is declared explicitly and has to be defined outside the class, which of the following is correct? 

This question was previously asked in
UGC NET Computer Science (Paper 2) 11 March 2023 Official Paper
View all UGC NET Papers >
  1. Date :: Date(int dd) {/*...*/}
  2. explicit Date:: Date(int dd) {/*...*/}
  3. Such a constructor cannot be defined
  4. Constructor always has to be defined inside the class

Answer (Detailed Solution Below)

Option 1 : Date :: Date(int dd) {/*...*/}
Free
UGC NET Paper 1: Held on 21st August 2024 Shift 1
8.7 K Users
50 Questions 100 Marks 60 Mins

Detailed Solution

Download Solution PDF

The correct answer is Date :: Date(int dd) {/*...*/}

Key PointsWhen we declare the constructor inside the class we could use the explicit keyword to prevent implicit conversions:

       class Date {
           explicit Date(int dd);  
    };

But when defining it outside the class, we should not include the explicit keyword:

    Date :: Date(int dd) {/*...*/}

So, the correct answer is Date :: Date(int dd) {/*...*/}

Additional InformationA constructor in object-oriented programming is a special type of subroutine (function or method) called to create an object. It prepares the new object for use, often accepting arguments that the constructor uses to set member variables required.

In C++, the constructor is a special function with the same name as the class which is automatically called whenever an object of the class is created. It is used to initialize the object of its class. Here's some basic features of constructors:

  • It should be declared in the public section of a class.
  • It is automatically invoked whenever an object is created.
  • It cannot return values and doesn't have a return type, not even void.
  • An error occurs if you declare a constructor with a return type.
  • It can have default arguments.
  • We cannot refer to their address.
  • It can be overloaded with different parameters.
Latest UGC NET Updates

Last updated on Jun 6, 2025

-> The UGC NET Exam Schedule 2025 for June has been released on its official website.

-> The UGC NET Application Correction Window 2025 is available from 14th May to 15th May 2025.

-> The UGC NET 2025 online application form submission closed on 12th May 2025.

-> The June 2025 Exam will be conducted from 21st June to 30th June 2025

-> The UGC-NET exam takes place for 85 subjects, to determine the eligibility for 'Junior Research Fellowship’ and ‘Assistant Professor’ posts, as well as for PhD. admissions.

-> The exam is conducted bi-annually - in June and December cycles.

-> The exam comprises two papers - Paper I and Paper II. Paper I consists of 50 questions and Paper II consists of 100 questions. 

-> The candidates who are preparing for the exam can check the UGC NET Previous Year Papers and UGC NET Test Series to boost their preparations.

More OOPs concept Questions

Get Free Access Now
Hot Links: teen patti game teen patti win teen patti master apk teen patti all games