File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Overriding/Hiding Interface variables

 
ashwin bhawsar
Ranch Hand
Posts: 62
Eclipse IDE
  • 0
  • 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
  • 0
  • 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
  • 0
  • 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: 47232
52
  • 0
  • 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
  • 0
  • 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: 20372
44
Chrome Eclipse IDE Java Windows
  • 0
  • 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: 47232
52
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Nothing wrong with the link http://www.coderanch.com/how-to/java/OverridingVsHiding
 
Don't get me started about those stupid light bulbs.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic