编译器生成的默认构造函数将是公共的吗? [英] Will the compiler-generated default constructor be public?
本文介绍了编译器生成的默认构造函数将是公共的吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
当我写一个类 Widget.java
public class Widget {
int data;
String name;
}
编译器生成的构造函数是 public 还是 default ?
will the compiler-generated constructor be public or default?
公众会喜欢
public class Widget {
int data;
String name;
public Widget() {}
}
默认类似于
public class Widget {
int data;
String name;
Widget() {}
}
推荐答案
这取决于您的类可见性.编译器使用类可见性,并使用生成无参数的默认构造函数可见度相同
It depends on your class visibility.The compiler uses the class visibility and generates a no-arg default constructor with the same visibility
这篇关于编译器生成的默认构造函数将是公共的吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文