Yes, we can declare a class as private but these classes can be only inner or nested classes. We can’t a top-level class as private because it would be completely useless as nothing would have access to it.
Java interview questions on access modifiers
- what are access modifiers in java?
- What are different types of access modifiers in java?
- What are non access modifiers in java?
- Can we use abstract and final both with a method?
- Can abstract class have final methods in java?
- Can we declare a class as private in java?
- Can we declare an abstract method as private?
- Can we declare a class as protected in java?