File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
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
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "Regarding Anonymous Inner Calss" Watch "Regarding Anonymous Inner Calss" New topic
Author

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.pop();
//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();
a.Ano();
}
}

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
Sheriff

Joined: Aug 03, 2008
Posts: 9280
    
  17

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: http://aspose.com/file-tools
 
subject: Regarding Anonymous Inner Calss
 
Similar Threads
Constructor in Anonymous inner class
Anonymous inner classes
Argument-defined anonymous class call
Is there a way to instantiate anonymous inner class?
Inner Class inside a method