Welcome Guest ( Log In | Register )




                Web Hosting Guide

 
Reply to this topicNew Topic
Override Or Shadow Interface Constant Variable
magiccode9
post Dec 10 2008, 11:01 PM
Post #1


Advanced Member
Group Icon

Group: [HOSTED]
Posts: 160
Joined: 7-November 05
Member No.: 9,489
myCENTs:36.33


I have played around java object and interface to see how they work together.
I think it is not that hard to understand, but, I came with a question now.

What the java tutorial said (downloaded from Sun web site)
an interface constant literal variable are implicity declared as

public, static, final

It is fine and correct when an interface implmented by a class and tried assign a value to it and reported an error.

But what confused me is I can declare a variable named the same as the interface do in a class that implemented it, and it don't produce any errors.
If I'am not wrong, c# would rasie an error.

CODE
public interface IInterace()
{
    int state = 0; /* implicity public state final */
}

public class AClass implements IInterface
{
   int state = 1; /* is this override or shadowed ? */
}


Any ideas would be appreciated .

Thanks,
Go to the top of the page
 
+Quote Post
turbopowerdmaxst...
post Dec 11 2008, 09:14 AM
Post #2


Premium Member
Group Icon

Group: [HOSTED]
Posts: 447
Joined: 16-February 06
From: Kolkata, India
Member No.: 11,322
myCENTs:81.67


I tested the code with Netbeans 6.1 and it seems like the variable is hidden by the one declared in the class. As for C#, you cannot declare variables in Interfaces.
Go to the top of the page
 
+Quote Post
magiccode9
post Dec 14 2008, 02:35 PM
Post #3


Advanced Member
Group Icon

Group: [HOSTED]
Posts: 160
Joined: 7-November 05
Member No.: 9,489
myCENTs:36.33


At which java sdk you based-on ?
I have tested it under jdk 1.3.1

It is confused me whether should I treat it as normally
or completely avoid use of it ...
Go to the top of the page
 
+Quote Post

Reply to this topicNew Topic
1 User(s) are reading this topic (1 Guests and 0 Anonymous Users)
0 Members:

 

Collapse

> Similar Topics

    Topic Title Replies Topic Starter Views Last Action
No New Posts   8 Supa Comix 8,539 29th January 2010 - 05:34 PM
Last post by: 8ennett
No New Posts 3 SiSTeMo 869 28th August 2009 - 04:51 PM
Last post by: Eggie
No New Posts   7 Eggie 1,418 27th September 2008 - 10:59 AM
Last post by: Eggie
No New Posts   9 TavoxPeru 4,987 19th May 2008 - 12:12 PM
Last post by: iGuest
No New Posts   11 jbitkill 1,645 5th November 2007 - 04:07 PM
Last post by: .:Brian:.
No New Posts   6 Herbert 1,048 11th October 2007 - 09:57 PM
Last post by: iGuest
No New Posts   1 sparkx 910 24th June 2007 - 11:20 PM
Last post by: Quatrux
No New Posts   1 Omkar™ 697 26th February 2007 - 06:56 PM
Last post by: BuffaloHELP
No New Posts 5 turbopowerdmaxsteel 1,232 24th January 2007 - 05:57 AM
Last post by: uapconsole
No New Posts   1 Jeigh 702 27th December 2006 - 10:56 PM
Last post by: leafbunk
No New Posts   5 tansqrx 2,979 21st November 2006 - 04:02 AM
Last post by: faulty.lee
No New Posts   13 bakr_2k5 2,157 20th November 2006 - 03:39 PM
Last post by: bakr_2k5
No New Posts 5 Kid Saiyan 1,665 23rd May 2006 - 06:48 PM
Last post by: Shadow X
No New Posts   12 david_ytk 2,038 20th May 2006 - 05:46 AM
Last post by: yeh
No New Posts   2 shadow-x 872 18th April 2006 - 01:42 AM
Last post by: OpaQue


Web Hosting Powered by ComputingHost.com.
HONESTY ROCKS! truth rules.
Creative Commons License