Computer Applications
What condition(s) a function must specify in order to create objects of a class ?
Java Constructors
5 Likes
Answer
Every time an object is created, the constructor is automatically invoked. If the function creating the object, does not have access privilege for the constructor, it cannot be invoked for that function. Thus, the object cannot be created by such function.
Therefore, it is essential for a function to have access privilege for the constructor in order to create objects of a class.
Answered By
4 Likes
Related Questions
Here is a skeleton definition of a class :
class Sample { int i; char c; float f; : //public members : }Implement the constructor.
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.
Constructor functions obey the usual access rules. What does this statement mean ?
How are parameterized constructors different from non-parameterized constructors?