• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Regarding Anonymous Inner Calss

 
Ranch Hand
Posts: 96
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Sheriff
Posts: 9707
43
Android Google Web Toolkit Hibernate IntelliJ IDE Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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....
reply
    Bookmark Topic Watch Topic
  • New Topic