This week's book giveaway is in the Mac OS forum.
We're giving away four copies of a choice of "Take Control of Upgrading to Yosemite" or "Take Control of Automating Your Mac" and have Joe Kissell on-line!
See this thread for details.
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes Relation between Interface Varable Declaration Same Implementar variable Declarateion Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "Relation between Interface Varable Declaration Same Implementar variable Declarateion" Watch "Relation between Interface Varable Declaration Same Implementar variable Declarateion" New topic
Author

Relation between Interface Varable Declaration Same Implementar variable Declarateion

Rajiv Chopra
Ranch Hand

Joined: Dec 19, 2008
Posts: 62
Hi,
Can some one explain me If we declare an variable in Interface and declare the same variable in Implementation. What is their relation and how they behave.
I am confused always with such type of declartion.
Thanks in advance.

public Interface TestAble{
public static final int i = 10;
}

public class ToTest implements TestAble{
public static final int i = 11;

}

public class Test extends ToTest{

public static void main(String[] args){

System.out.println( "What Value of i should be here" + i); // Interface value or ToTest int value and why??

}


Thanks
In Advance....


Rajeev Kumar
SCJP 6.0 Certified 96%
Neha Daga
Ranch Hand

Joined: Oct 30, 2009
Posts: 504
interface variable will be hidden by the implementing class's variable.


SCJP 1.6 96%
Rajiv Chopra
Ranch Hand

Joined: Dec 19, 2008
Posts: 62
Neha Daga wrote:interface variable will be hidden by the implementing class's variable.


Thanks for Reply..

If implementing class has same varable name even String (public static final String i = "Some String"; ) then also it will hide the Interface variable.

Thanks I think after reply from you guys i will not forget.

rushikesh sawant
Ranch Hand

Joined: Dec 22, 2009
Posts: 65
yes, it works same even if it is a string.


SCJP 5.0 100%
 
GeeCON Prague 2014
 
subject: Relation between Interface Varable Declaration Same Implementar variable Declarateion