user2653335
user2653335

Reputation: 13

Inheritance of static final --> not visible

Hey guys I am a total java newbie and to be honest I am not sure on how to explain my problem to you.

So I have 2 classes, one of which is inherited by the other.

Now I am not allowed to change the superclass, or else this would be much easier.

The problem is that in my subclass I want to access a variable (let's call it variable1)

This variable is defined like following in the superclass:

static final String variable1 = (String)AccessController.doPrivileged(new PrivilegedAction()
 {
    public Object run() {
        return System.getProperty("variable1", "\n");
    }
 }
);

Now in my subclass I try the following:

this.finalOutputFormat = (replaceKeys(this.format) + variable1);

But it doesn't work because eclipse keeps telling me that variable1 "is not visible".

That is pretty much the only error I've got.

Do you have any idea why variable1 is not visible to my subclass? The superclass is imported as a library but in a different package, obviously.

I hope my description of the situation is not too confusing but right now I don't have much more information than this.

Thanks.

Upvotes: 0

Views: 860

Answers (2)

charles_ma
charles_ma

Reputation: 786

if you want to use it like this, put a public modifier before variable1 or move sub class to the same package as super class

Upvotes: 0

Arnaud Denoyelle
Arnaud Denoyelle

Reputation: 31225

There is no visibility keyword (public, private, protected) on variable1. Hence, it is only accessible from classes which are in the same package.

If you are not allowed to modify your superclass, your only option is to put your class in the same package as the superclass.

Upvotes: 4

Related Questions