mULTIPLE iNHERTANCE FOR mEMBER TYPES IN iNTERFACES jAVA

hI ,

Iam trying to implement the issues we get when we inherit two interfaces with same member type name , I should get the member type name ambiguity error , but not getting it. Any help is really appreciated.

public interface Bank
{
      interface Card
      {
            String getCardType();
      }
}

public interface ATM
{
      boolean login (int acctno);
      interface Card
            {
                  double getamt(int acctNo);
            }
}

public interface DummyBank extends ATM, BANK
{
int getChequeDepositedDetails(int acctno);
}


-- Should produce an error for member type name  when compiled ambiguity , but not getting it.
public class SBIBankImpl implements DummyBank  
{

public String getCardType()
{
return "SBI DEBIT CARD";
}

public boolean login (int acctno)
{
return true;
}

public double getamt(int acctNo)
{
return 10000.03;
}

public int  getChequeDepositedDetails(int acctno)
{
return 1233444444;
}

public static void main (String [] args)
{
SBIBankImpl c = new SBIBankImpl();
String name=c.getCardType();

System.out.println(name);

}
}
sam_2012Asked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

CPColinSenior Java ArchitectCommented:
I'm pretty sure you get the error for non-static members only. Nested interfaces are static, so there's no problem.
0
sam_2012Author Commented:
Hi

We will get an error when we have two interfaces with member types with same name even though they are static or non static , I should get ambiguity error.
0
sam_2012Author Commented:
public interface Bank
{
int Yes=1;

}

public interface ATM
{
     int Yes=2;
     
}

public interface DummyBank extends ATM, BANK
{
int ans=Yes;
}

Throws as ambiguity error telling which interface constant value to use.  Similar to this I should get an error for member types in Interface.
0
Cloud Class® Course: MCSA MCSE Windows Server 2012

This course teaches how to install and configure Windows Server 2012 R2.  It is the first step on your path to becoming a Microsoft Certified Solutions Expert (MCSE).

CPColinSenior Java ArchitectCommented:
Well, sure, in that example, the compiler has no way of knowing whether you mean Bank.Yes or ATM.yes. In your first example, you're not making any references to Bank.Card or ATM.Card, so there's no problem.
1
sam_2012Author Commented:
Yes, I need an example which will throw an error for the member types , any help in this regard is really appreciated .
0
CPColinSenior Java ArchitectCommented:
interface A
{
   default int getValue()
   {
      return 0;
   }
}

interface B
{
   default int getValue()
   {
      return 1;
   }
}

class AB implements A, B
{
   // This produces an error because the compiler can't tell if you want
   // A.getValue() or B.getValue() to run when somebody calls AB.getValue().
}

Open in new window

1
sam_2012Author Commented:
I want the  example with either Nested Interface or Nested Classes name collision
0
mccarlIT Business Systems Analyst / Software DeveloperCommented:
To see the error being reported, you need to attempt the define a class that implements   DummyBank.Card    and at that point it doesn't know which Card, ATM or Bank, to implement. eg.

Just trying to start to define this class...

public class CardImpl implements DummyBank.Card {
}

gives the error. But if you comment out one of ATM.Card  or Bank.Card interface definition lets you define the above class just fine.
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
CPColinSenior Java ArchitectCommented:
I want the  example with either Nested Interface or Nested Classes name collision

I can't think of one. It seems unlikely to happen in real code.
0
sam_2012Author Commented:
public class CardImpl implements DummyBank.Card {
}

Iam not getting the error , its says cannot find the symbol.
0
mccarlIT Business Systems Analyst / Software DeveloperCommented:
Have you got that in a different package or anything like that ? Also what version of Java are you compiling with?
0
sam_2012Author Commented:
Java 1.8 version
0
mccarlIT Business Systems Analyst / Software DeveloperCommented:
Hmmm, not sure then. Can you post the full error? Maybe a screenshot so we know exactly what it is referring to, etc?
0
sam_2012Author Commented:
Sorry , I tried to implement the same and it worked.
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Java

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.