Do you want to override (for absence of a better word) a function in the inner class of the parent class. Here is a good way of doing it:
Hence, following method shall print:
Whenever you want to instantiate a Room of a House (either a House or a Bungalow), use the getRoom() method of the House.class House { public class Room { public int minLength() { return 100; } } public Room getRoom() { return new Room(); } } class Bungalow extends House { public class Room extends House.Room { @Override public int minLength() { return 1000; } } @Override public Room getRoom() { return new Room(); } }
Hence, following method shall print:
on the screen:100 1000
public static void main(String args[]){ House h=new House(); System.out.println(h.getRoom().minLength()); h=new Bungalow(); System.out.println(h.getRoom().minLength()); }
Comments
http://www.wikitechy.com/view-article/nested-classes-in-java-with-example
Both are really good,.
Cheers,
Venkat