Some people might get confused by the many posts. The correct answer to the question "can we declare class as protected?" is YES, BUT only as an inner class. A 'normal' class cannot be protected or private.
// 'Normal' class - only default or public allowed
public class ProtectedOrNot {
// Inner class - public, default, protected, private allowed
protected class InnerClass {
}
public static void main(String[] args) {
}
}
Above answer was rated as good by the following members: iitd.mayank
RE: can we declare class as protected?what is th...
Yes we can declare a class as protected however its sub-classes (inherited) can only use the objects of that class then. It will not be possible to access the functions of that class with other class's objects.
RE: can we declare class as protected?what is th...
1. No You can't declare a class as protected. because compiler will give you Compile time error.2. You can decalre a class a public or default. if you don't mention any access specifier by default it will take class as default access specifier