为什么我应该使用构造函数来初始化实例变量,虽然在它们的声明点是可能的?
class Frog {
public int x = 4;
Frog() { // Why should I use you }
}
最佳答案
You should use me because I will help you keep your initializations in one place. Because it will help you other colleagues to know where to expect initializations and not miss one if they're scattered aroudn the code.
关于java - 如果我可以用另一种方式初始化实例变量,为什么还要使用构造函数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3923825/