Nov 22, 2009

Override Or Shadow Interface Constant Variable

free web hosting
Open Discussion & Free Web Hosting > Computers & Tech > Programming > Programming General > Java

Override Or Shadow Interface Constant Variable

magiccode9
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,

 

 

 


Comment/Reply (w/o sign-up)

turbopowerdmaxsteel
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.

Comment/Reply (w/o sign-up)

magiccode9
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 ...

Comment/Reply (w/o sign-up)


Got an Opinion! Express your Views! (no registration):-
Add your Reply/ Opinion/ Views/ Comments/ Suggestion/ Questions/ Queries etc.
Posts with decent grammar & English will be accepted and please refrain from profanities.
For asking a Question, We recommend you to sign-up (for free) so that you can track the topic easily.

Nature of your Post*: Opinion/ Reply/ Comments
Question/Query
Feedback to us.
       
Name   Email
Title/Question*

This textarea will convert to Rich-Text automatically (IE, Firefox, Chrome)


See Also,

*SIMILAR VIDEOS*
Searching Video's for Override, Shadow, Interface, Constant, Variable
advertisement



Override Or Shadow Interface Constant Variable

Affordable Web Hosting, Low cost Web Hosting - ComputingHost.com