Friday, February 27, 2009

example code Anonymous inner class

package innerclass;

class Popcorn
{
public void eat()
{
System.out.println("so sweet");
}
}
public class Sample
{
public static void main(String arg[])
{
Popcorn p=new Popcorn() // no semicolon (;) here
{
public void eat()
{
System.out.println("so spicy");
}
}; // with out semicolon (;) leads compile time error
p.eat(); // so spicy
}
}


0 comments:

Post a Comment