• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Relation between Interface Varable Declaration Same Implementar variable Declarateion

 
Rajiv Chopra
Ranch Hand
Posts: 62
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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....
 
Neha Daga
Ranch Hand
Posts: 504
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
interface variable will be hidden by the implementing class's variable.
 
Rajiv Chopra
Ranch Hand
Posts: 62
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 65
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
yes, it works same even if it is a string.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic