Does enum need to be defined as "public" in its own file so that it can be recognized outside its own package?

I have two packages - x and y.

x contains the Student class and the Grade enumeration.

y contains the class Klass .

Why is the Student.Grade.C type not recognized in the Klass class in package y?

Do I need to define it in my own file and publish it?

 package x; enum Grade { A, B, C, D, F, INCOMPLETE }; public class Student { // blah, blah, member variables, getters, setters, constructors } package y; public class Klass { // This enum type is not recognized in this package public static final MINIMUM_GRADE = Student.Grade.C; } 
+4
source share
2 answers

Yes, you must declare this enum public. You do not have to have it in your own file.

You will get access, like your example Student.Grade.C ;

You can import Student.Grade and just use C in your code.

+9
source

Without using public , protected or private , the transition class has a default access level - this means only other classes in the same package can use it.

+3
source

All Articles