-2
interface A
{
    public boolean bA=true;
    public boolean bB=true;
    public boolean bC=true;


}
interface B extends A
{
    boolean bA=false;/*(here bA i think is ambiguous how does compiler know which value to take )*
}

class C implements B
{
    public void printbool()
    {
        System.out.println("bA="+bA);
        System.out.println("bB="+bB);
    }
}
public class demointerface implements B{
public static void main(String []args)
{
    C c=new C();
    c.printbool();

     }
}

/*here OUTPUT is as follows


bA=false
bB=true
BUILD SUCCESSFUL (total time: 1 second)

*/

Edited by mike_2000_17: Fixed formatting

3
Contributors
2
Replies
3
Views
7 Years
Discussion Span
Last Post by JamesCherrill
0

Dont hide your questons inside your unformatted code which is even without code tags.
Be specific about your problem. That way we can help you better.
Keep that in mind and read the community rules before posting.
Good Luck.

0

When you extend a class or interface, any members that you re-define in the subclass/interface override the definition in the superclass/interface.
So there is no ambiguity.
If you have an instance of B then the definition in B applies (if it is not defined in B, then it inherits the definition from A), if you have an instance of A then the definition in A applies.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.