aspose file tools
The moose likes Java in General and the fly likes can a interface variable be re assigned in abstract class Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login
JavaRanch » Java Forums » Java » Java in General
Reply Bookmark "can a interface variable be re assigned in abstract class" Watch "can a interface variable be re assigned in abstract class" New topic
Author

can a interface variable be re assigned in abstract class

sudheer kiran
Ranch Hand

Joined: Jun 26, 2008
Posts: 237

by default interface variables are public static final then what if the implementing class defines the same variable.

example here


Sudheer
SCWCD, SCJP 5
Manish Singh
Ranch Hand

Joined: Jan 26, 2007
Posts: 160
the two "i" in the interface and class are different so there wont be any problem.

The variables in the interfaces are implicitly "public static and final" .

Anant Jagania
Ranch Hand

Joined: Oct 20, 2004
Posts: 49
int i = 20; // why doesnt not it give error,as it is over riding the interface variable.


You cannot override interface/class variable in subclass or implementing class.

Only methods can be overridden.

Hence, variable "i" is different in interface and class.

In your example variable "i" for Interface is static final variable which is accessible globally while variable "i" in Abstract class is accessible only by the class.
sudheer kiran
Ranch Hand

Joined: Jun 26, 2008
Posts: 237

how they both i's are different. interface final variables are inherited to implementing class.
in the implementing class how you can assign a new value.
sudheer kiran
Ranch Hand

Joined: Jun 26, 2008
Posts: 237



it seems the problem is not related to statics, i think variables(including final variables) can be redefined in subclass.
 
I agree. Here's the link: jrebel
 
subject: can a interface variable be re assigned in abstract class
 
Similar Threads
diff between abstract class and inheritance
Class within Interface
interface
Marcus Green Exam 2 questions
declaring an array using an interface type