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)
*/
fsl4faisal -4 Newbie Poster
Recommended Answers
Jump to PostWhen 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 …
All 2 Replies
NP-complete 42 Junior Poster
JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster
Be a part of the DaniWeb community
We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.