How to access the method, anonymousMethod(), so that the, System.out.println("Entered anonymousMethod() inside the anonymous class."); will be printed?
Can any of you ranchers clarify me the same?
SCJP 6.0 90%
Joined: Sep 13, 2004
You have to assign your class to a variable to call its method..
Joined: Feb 22, 2006
well I think anonymous inner classes are created by extending the class u are instantiating and if u define any method that cannot be accessed by the reference type then u cant call the method due to the fact that at compile time the methods that can be called on an object is being determined by the reference type.
Da Clone in programming world
Joined: Mar 09, 2006
Thanks for the clarifications. So we can create reference variables for the class or interface we are extending while creating anonymous inner classes. and the method iam writing inside the anonymous inner class are the ones defined in these extending class or interface. In other words i can only override the methods of the extending class or interface? and cannot write any other new methods not defined in the parent class or interface iam extending?