This week's book giveaway is in the Jobs Discussion forum.
We're giving away four copies of Java Interview Guide and have Anthony DePalma on-line!
See this thread for details.
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes Regarding Anonymous Inner Calss Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Java Interview Guide this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "Regarding Anonymous Inner Calss" Watch "Regarding Anonymous Inner Calss" New topic

Regarding Anonymous Inner Calss

Deepak Bobal
Ranch Hand

Joined: Feb 06, 2008
Posts: 96
class Outer1
void pop()
System.out.println("In Outer1");

class Anony
void Ano()
Outer1 o=new Outer1()
{// Statring brace of Anonymous subclass of Outer1
void pop()
System.out.println("Welcome To pop");

void jazz()
System.out.println("Welcome To Jazz");
}; //closing off the Anonymous class
//o.jazz(); will give error as "cannot resolve symbole" as Super class reference variable is not familier with the methods those are declared only in Subclass (Here Anonymous class)

public class PolymorAnonyClass
public static void main(String []arg)
Anony a=new Anony();

As in the above piece of code it's not possible to call jazz() with the superclass reference.

So how jazz() can be called?

Thank You
Deepak Bahubal

Constant dripping hollows out a stone....
Ankit Garg

Joined: Aug 03, 2008
Posts: 9466

jazz can only be called within other members of the anonymous inner class. You cannot call it from instance of the anonymous class by any means as it is not overriding any super-class member....

SCJP 6 | SCWCD 5 | Javaranch SCJP FAQ | SCWCD Links
I agree. Here's the link:
subject: Regarding Anonymous Inner Calss
It's not a secret anymore!