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/interfa
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:
public interface EmailService {
void send(EmailDetails details);
class EmailDetails {
private String from;
private String to;
private String messageTemplate;
// etc...
}
}