Examine the following class definition:
class DateType
{
public:
void Initialize(int, int, int);
int GetYear() const; // returns year
int GetMonth() const; // returns month
int GetDay() const; // returns day
private:
int year;
int month;
int day;
};
Which of the following statements in a client program correctly prints out the day of the variable day1 of type DateType?
A. cout << day1.GetDay;
B. cout << day1.GetDay();
C. cout << GetDay.day1;
D. cout cout << GetDay(day1);
E. The day cannot be printed by a client program.

Answer :

Answer:

The answer is "Option B"

Explanation:

In the given code, a class "DateType" is declared, inside the class, four methods "Initialize, GetYear, GetMethod, and GetDay" is defined, in which the "Initialize" method does not return any value and other methods return a constant type value, which means it value can't be changed.

Inside the class three integer variable is defined, that is"year, month, and  day".  In the "GetDay" method call, it first creates the class object "day1", which is already defined in question and call the method by dot (.), that's why only choice b is correct.

Other Questions