Can somebody tell me what does this mean? I'm going trough Java book and I've encontered this example :
public class Message {
Message(){}
public Message(String text){
this.text = text;
}
What does Message(){}
Mean ?
It's a package private empty constructor taking no arguments.
You can use it to create a new Message instance from any code in the same package, by using new Message();
.
It's worthwhile to know it will not initialize the text
field, which will therefore hold the default null
value.
just like
Message()
{
}
but using less lines.
the access level for it is the (default) package access level meaning only classes within the same package can instantiate this object using this constructor.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With