File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes doubt in interface variables.. Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "doubt in interface variables.." Watch "doubt in interface variables.." New topic
Author

doubt in interface variables..

Sriram.Narayanan Thiagarajan
Greenhorn

Joined: Jul 21, 2006
Posts: 26
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

Naveen Zed
Ranch Hand

Joined: Aug 11, 2006
Posts: 61
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
Gowher Naik
Ranch Hand

Joined: Feb 07, 2005
Posts: 643
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

Joined: Feb 07, 2005
Posts: 643

check code Above.
Sriram.Narayanan Thiagarajan
Greenhorn

Joined: Jul 21, 2006
Posts: 26
Interface variables are implicitly final
Then how come we redeclare an interface variable
Awais Sheikh
Ranch Hand

Joined: Jun 07, 2006
Posts: 48
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

Joined: Jul 21, 2006
Posts: 26
understood

thanks Awais Sheikh
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: doubt in interface variables..
 
Similar Threads
Inheritence
cast null to interface and class
Strange Enum
why interface variables are static and final. what is reason to declare them as like that?
instanceof Q? for SCJP