• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

doubt in interface variables..

 
Greenhorn
Posts: 26
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi All,

interface I {int interfaceConstant =10;}

interface I1 extends I {int interfaceConstant=12;}

public class A implements I1
{
public static void main(String s[])
{
System.out.println(interfaceConstant);
}
}

output - 12

I don't understand why the o/p is 12

 
Ranch Hand
Posts: 61
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by T.Sriram.Narayanan Thiagarajan:
Hi All,

interface I {int interfaceConstant =10;}

interface I1 extends I {int interfaceConstant=12;}

public class A implements I1
{
public static void main(String s[])
{
System.out.println(interfaceConstant);
}
}

output - 12

I don't understand why the o/p is 12



I think the cause is due to the overriding between the inherited interfaces
 
Ranch Hand
Posts: 643
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
In java variables overriding is not possible.
In second interface you are redeclaring interfaceConstant variable
or you can say you are hidding first interfaceConstant by second interfaceConstant variable this is why you get output - 12
 
Gowher Naik
Ranch Hand
Posts: 643
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

check code Above.
 
Sriram.Narayanan Thiagarajan
Greenhorn
Posts: 26
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Interface variables are implicitly final
Then how come we redeclare an interface variable
 
Ranch Hand
Posts: 48
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Both Interface varibles are declaring, intializing and working seperately.
and there is not link b/w them. So which interface variable you will call you will get that value.
Hope you understand now.
thanks
 
Sriram.Narayanan Thiagarajan
Greenhorn
Posts: 26
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
understood

thanks Awais Sheikh
reply
    Bookmark Topic Watch Topic
  • New Topic