The below code is a simple inner class and understandable , also of late people do prefer using inner classe more espically Anonymous Inner Classes
Please do help me with Anonymous Inner Classes as its difficult tu understand except for the fact that its not re suable and good for coding on the fly .
Code:
public class First // Top-level class; outer class or enclosing class { int price = 100; // variable of outer class class Second // inner class as a member of outer class { int rate = 200; // variable of inner class public void display() // inner class method { System.out.println("price from display() method: " + price); System.out.println("rate from display method: " + rate ); } } // inner class closes public void show() // outer class method { System.out.println("price from show() method: " + price); // System.out.println("y from outer method: " + y); // raises compilation error, scope problem } public static void main(String args[]) { First f1 = new First(); First.Second fs = new First( ).new Second(); f1.show(); fs.display(); } }
Comment