I like to know can we define an interface within an interface.
like
interface abc {
void show();
public interface xyz {
void read();
}
}
This was question asked in interview. Any practical use of this.
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
Yes, we can do it. The definition of the nested interface in java is as follows:
Refer this for more.
Further …
One reason could be that the outer interface has a method that takes a callback implementation as an argument. The nested interface is, in that case, the contract that the callback method must implement. I don’t see a reason to declare that callback interface at the top level.
Another good reading at sun site about this topic is here
In particular, notice that when you implement an interface, you are
not required to implement any
interfaces nested within.