Java – can you write a constructor that does nothing?

To use class methods, I need to instantiate a class At present, this class has no constructor (so I want to write it) But I realized that the constructor does nothing (I need to specify the value of the field)

In this case, I have a problem if I write a constructor that doesn't do anything For example:

public Point() {
}

Solution

You don't need to write an empty constructor; The java compiler will automatically insert one for you (only if you don't define any other constructors and need some parameters)

So this is very good (useful in some cases), but not necessary

The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>