Can class defined inside Interface

Can class defined inside Interface

Answer: Yes it is possible to define class inside the interface in java but not recommended. Let’s see in example:

package com.javahonk;

public interface Employee {

    class Branch {
	String name = "";
	String location = "";

    }

}

 

Java allows us to create class inside interface and as you could see above. This doesn’t mean that its a good idea to define class inside interface this will make relationship between interface and class is very tightly coupled and nobody can live apart.

Leave a Reply

Your email address will not be published. Required fields are marked *