Re: Regarding Interface..
On Thu, 28 May 2009 21:57:36 -0700, frank <frank003@gmail.com> wrote:
Hi friends,
have some doubt in Interface...
they are.....
1. Why the Variables are Private static final in Interface..... where
all the methods
are Public...
What "private static final" variables? As far as I know, you can only
make the variables (fields) "final". The "private" and "static" can't be
applied.
As far as the specific question goes:
2. interface a
{
private static final int a=10;
}
interface b
{
private static final int a=50;
}
class c implements a,b
{
which value of 'a' is available Here....?
}
I run it but it show ambiguity Error ....
I think the Problem is in Multiple Inheritance is still in Java....?
It's kind of related to multiple inheritance, except that it has none of
the really problematic issues that come with true multiple inheritance.
After all, you're not going to find yourself in a polymorphic situation
where there's more than one possible interpretation of some code.
When you have the situation you describe (minus the "private static", of
course), the identifier has to be resolved at compile time, and you do
that by specifying the exact interface from which you want to get the
field:
class c implements a, b
{
void method()
{
int i = a.a, j = b.a;
}
}
You can do something similar for code trying to access the field through
the type "c".
Pete