Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Cloud/Virtualization forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

interfaces

 
amrit singh
Ranch Hand
Posts: 42
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi !!!
could ne one pls explain what happen
1)when a class implements two interfaces that declares same method.if possible with example
2)consider this
interface cintf{
void disp();
}
class cclass implements cintf{
public void disp(){}
public void another(){}
}
class test{
cintf c=new cclass();
//how can i access another() method here using refrence c
}
 
bill bozeman
Ranch Hand
Posts: 1070
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
For the first question, do it and see what happens. Here is some code you can use to play with. I am not trying to not give you the answer, I just want to help you play with code on your own and compile and test things. It is the best way to learn.

As for your second question, you can't access the class method if the type is an interface. You would need to cast it back down to the class to be able to access the method in the class.
Bill
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic