I got a question on an exam.
Does every .class (not .java) file contain a public class?
Yes? No?
I got a question on an exam.
Does every .class (not .java) file contain a public class?
Yes? No?
No, can have some classes as private, protected, default and public. From these four type
No, class files are generated (also) for less visible and even "inner" classes.
No access modifiers include public
, protected
, and private
.
Example:
public class foo {}
private class foo {}
protected class foo {}
You can also have a class without an access modifier.
class foo {}
However, if you want to be able to fully access your class from another class use the public
access modifier.
See here for more information : Examining Class Modifiers and Types