I have the superclass like this. package payroll; public class UserConnection { protected int users = 0; } and the subclass package client; import payroll.UserConnection; class ServerConnection extends UserConnection { public UserConnection getUserConnection() { UserConnection u = new UserConnection(); u.users += 1; return u; } } why the subclass is not compiling saying users variable is not accessible? I have imported superclass and the variable users is protected which means it is accessible in subclass isn't? What is the error here or how to make the subclass to work properly? Thanks.
This topic was just covered in this thread. The skinny of it is that you can't access that member because you're not using it in code that is responsible for the implementation of that class. Check out the JLS, §6.6.2.1 Access to a protected Member for more details. Corey
Originally posted by Ali Macky: You do not need to create an object of the base class. You can access the users variable directly.
Creating a new instance of the UserConnection class and modifying its users member is very different from modifying your own, inherited, users member. Be sure you know the difference. Corey