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 Anonymous inner class 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 "Anonymous inner class" Watch "Anonymous inner class" New topic

Anonymous inner class

Shiva Mohan
Ranch Hand

Joined: Jan 05, 2006
Posts: 481

Anonymous class method is sizzle().But Anonymous class instance(myAccess) is not accepting sizzle() method.Why and how can I access sizzle() method.Please help me.
Wally Valters

Joined: Jun 08, 2006
Posts: 3
As I see it you cannot. Because your anonymous inner class is a SUBCLASS of Popcorn and is being accessed by a reference of type Popcorn. So only methods defined in Popcorn (or its superclasses etc) can be accessed.
Shashidhar Gajula

Joined: Aug 05, 2006
Posts: 1
see the below code you will realize the things

class Popcorn {
public void pop() {



class MyInner{

//----------------------------outer class

Popcorn p=new Popcorn() {

//----------------------------anonymous inner class
public void sizzle() {

System.out.println("anonymous sizzing popcorn");


public void priya() {

(new Popcorn() {

//----------------------------anonymous inner class
public void sizzle() {

System.out.println("anonymous sizzing popcorn");

//---------------------------------will print Popcorn class pop()

class Objective15 {

public static void main(String[] args) {

MyInner outer=new MyInner();


Popcorn myAccess=outer.p;


// myAccess.sizzle();//--------------------------line1
I agree. Here's the link:
subject: Anonymous inner class
It's not a secret anymore!