OOPS
November 12, 2023
GATE 2022
November 12, 2023
OOPS
November 12, 2023
GATE 2022
November 12, 2023

NTA UGC NET DEC-2022 Paper-2

Question 11
If a constructor ‘Date’ is declared explicitly and has to be defined outside the class, which of the following is correct?
A
Date::Date(int dd) {/*…*/}
B
explicit Date::Date(int dd) {/*…*/}
C
Such a constructor cannot be defined
D
Constructor always has to be defined inside the class
Question 11 Explanation: 
Defining a Constructor Outside of the Class :Although the constructor can be defined outside of the class, it must be declared inside class. Use the scope resolution operator while defining a constructor outside of the class.
class class_name {
public:
class_name();
};

// Defining a Constructor Outside of the Class by using :: operator
class_name::class_name()
{
}

Correct Answer: A
Question 11 Explanation: 
Defining a Constructor Outside of the Class :Although the constructor can be defined outside of the class, it must be declared inside class. Use the scope resolution operator while defining a constructor outside of the class.
class class_name {
public:
class_name();
};

// Defining a Constructor Outside of the Class by using :: operator
class_name::class_name()
{
}

Leave a Reply

Your email address will not be published. Required fields are marked *