Win a copy of Mesos in Action this week in the Cloud/Virtualizaton forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Overriding/Hiding Interface variables

 
ashwin bhawsar
Ranch Hand
Posts: 62
Eclipse IDE
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Why is it allowed to override interface variables. Interfaces are meant to be followed as it is, then why a class is allowed to override the variable from an interface.

 
Seetharaman Venkatasamy
Ranch Hand
Posts: 5575
Eclipse IDE Java Windows XP
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
ashwin bhawsar wrote:


No, It is not overriding . it is redefining.
ashwin bhawsar wrote:

what happen when you try
I a = new A();
System.out.println(a.staticVar);
 
kunal Agarwal
Greenhorn
Posts: 15
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Variables in Interfaces can never be changed, as they are implicitly static final....


in the above code...i don't think it's overriding/hiding static variable from interface...it seems the variable i from the interface it's completely off the radar in subclass..we can still access it using sclass.i in the main...

The code you posted...used static hiding concept as already explained..what about this one?
 
Campbell Ritchie
Sheriff
Pie
Posts: 48976
60
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Still hiding. We have an FAQ about that problem.
 
ashwin bhawsar
Ranch Hand
Posts: 62
Eclipse IDE
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
@Campbel
the FAQ link is bad.Do you have another link ?
 
Rob Spoor
Sheriff
Pie
Posts: 20532
54
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
How is it bad? It's working for me, and opens the relevant FAQ entry.
 
Campbell Ritchie
Sheriff
Pie
Posts: 48976
60
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Nothing wrong with the link http://www.coderanch.com/how-to/java/OverridingVsHiding
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic