• Post Reply Bookmark Topic Watch Topic
  • New Topic

can a interface variable be re assigned in abstract class  RSS feed

 
sudheer kiran
Ranch Hand
Posts: 237
Firefox Browser MyEclipse IDE Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
by default interface variables are public static final then what if the implementing class defines the same variable.

example here
 
Manish Singh
Ranch Hand
Posts: 160
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 49
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 237
Firefox Browser MyEclipse IDE Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 237
Firefox Browser MyEclipse IDE Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator


it seems the problem is not related to statics, i think variables(including final variables) can be redefined in subclass.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!