Sunday, July 01, 2007

Class in Interface

One can have a class in an interface using nested classes (i.e. static inner classes).


public interface ClassInInterface {
void helloWorld();

class Test implements ClassInInterface {
public void helloWorld() {
System.out.println("Hello World!");
}
public static void main(String[] args) {
new Test().helloWorld();
}
}


The inner class in an interface is nested class - it is public and static.





<< Home

This page is powered by Blogger. Isn't yours?