member-access

Will the compiler-generated default constructor be public?

隐身守侯 提交于 2019-12-01 01:54:26
问题 When I write a class Widget.java public class Widget { int data; String name; } will the compiler-generated constructor be public or default ? public would be like public class Widget { int data; String name; public Widget() {} } whereas default similar to public class Widget { int data; String name; Widget() {} } 回答1: It depends on your class visibility .The compiler uses the class visibility and generates a no-arg default constructor with the same visibility 回答2: As said in JLS If a class