Im trying to declare a protected variable inside a protected class but get an error,
protected class Car {
protected int x = 9;
}
The valid modifier for the class is public, abstract and final as per Eclipse.
Can someone please explain?
Im trying to declare a protected variable inside a protected class but get an error,
protected class Car {
protected int x = 9;
}
The valid modifier for the class is public, abstract and final as per Eclipse.
Can someone please explain?
A class (or interface) cannot be protected, only fields and methods within a class can be. However, there is an exception where if you have nested (or inner) classes or interfaces you can in fact label them as protected. I am assuming that your class is a top level class though, hence why you are receiving an error message.