This week's book giveaways are in the Refactoring and Agile forums.
We're giving away four copies each of Re-engineering Legacy Software and Docker in Action and have the authors on-line!
See this thread and this one for details.
Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Cloud/Virtualization forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Regarding Anonymous Inner Calss

 
Deepak Bobal
Ranch Hand
Posts: 96
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
Ankit Garg
Sheriff
Posts: 9509
22
Android Google Web Toolkit Hibernate IntelliJ IDE Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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....
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic