Computer Applications
Define a constructor function for a Date class that initializes the Date objects with given initial values. In case initial values are not provided, it should initialize the object with default values.
Java Constructors
10 Likes
Answer
public Date()
{
day = 1;
month = 1;
year = 1970;
}
public Date(int d, int m, int y)
{
day = d;
month = m;
year = y;
}
Answered By
6 Likes
Related Questions
Can you think of the benefits of a private class if any ? What are they ?
Here is a skeleton definition of a class :
class Sample { int i; char c; float f; : //public members : }
Implement the constructor.
What condition(s) a function must specify in order to create objects of a class ?
Constructor functions obey the usual access rules. What does this statement mean ?