Nice post, well explained, i like it, if i would teach in a future some OO language i would go back to this post as a reference. I would like to add two little conceptual details.
In Java a default constructor is constructor that gets generated if you don't explicitly create one. That's the reason why you can create and no-param object without creating an explicitly constructor.
Finally, i would like to add that in the above example "chris" works as a reference of an object assigned to an object in memory.
Regarding the default constructor, I thought it would be a correct way of calling it since that implementation of the Person class does not allow the client of our code to create an object without passing any arguments to it. Would it be better to say "overriding the default constructor"?
Thanks to you, i really like it as an introduction for classes, you should continue doing this kind of post.
I considered can be called just param-constructor, if we explicitly add no-args-contructor can be called as a overloaded constructor. The Overrinding is not possible for constructors because the behavior strictly belongs to the class.
For further actions, you may consider blocking this person and/or reporting abuse
We're a place where coders share, stay up-to-date and grow their careers.
Nice post, well explained, i like it, if i would teach in a future some OO language i would go back to this post as a reference. I would like to add two little conceptual details.
In Java a default constructor is constructor that gets generated if you don't explicitly create one. That's the reason why you can create and no-param object without creating an explicitly constructor.
Finally, i would like to add that in the above example "chris" works as a reference of an object assigned to an object in memory.
Thanks for the tips, Gustavo.
Regarding the
default constructor
, I thought it would be a correct way of calling it since that implementation of the Personclass
does not allow the client of our code to create an object without passing any arguments to it. Would it be better to say "overriding the default constructor"?Thanks to you, i really like it as an introduction for classes, you should continue doing this kind of post.
I considered can be called just param-constructor, if we explicitly add no-args-contructor can be called as a overloaded constructor. The Overrinding is not possible for constructors because the behavior strictly belongs to the class.