Q1. Can I have an interface inside a class in java?
Q2. Can I have an class inside an interface?
If yes, then in which situations should such classes/interfaces used.
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.
Q1. Yes Q2. Yes.
Inside your class you may need multiple implementations of an interface, which is only relevant to this particular class. In that case make it an inner interface, rather than a public / package-private one
In your interface you can define some data holder classes that are to be used by implementations and clients.
One example of the latter: