aspose file tools*
The moose likes Beginning Java and the fly likes Overriding/Hiding Interface variables Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Overriding/Hiding Interface variables" Watch "Overriding/Hiding Interface variables" New topic
Author

Overriding/Hiding Interface variables

ashwin bhawsar
Ranch Hand

Joined: Mar 16, 2011
Posts: 62

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

Joined: Jan 28, 2008
Posts: 5575

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

Joined: Aug 15, 2011
Posts: 15
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

Joined: Oct 13, 2005
Posts: 39380
    
  28
Still hiding. We have an FAQ about that problem.
ashwin bhawsar
Ranch Hand

Joined: Mar 16, 2011
Posts: 62

@Campbel
the FAQ link is bad.Do you have another link ?
Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19718
    
  20

How is it bad? It's working for me, and opens the relevant FAQ entry.


SCJP 1.4 - SCJP 6 - SCWCD 5 - OCEEJBD 6
How To Ask Questions How To Answer Questions
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 39380
    
  28
Nothing wrong with the link http://www.coderanch.com/how-to/java/OverridingVsHiding
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Overriding/Hiding Interface variables