Anonymous Class example


interface MyShape {
static double pi = 3.14;
public double area() ;
public void setValue(int v);
}

public class AnonymousExample
{

public static void main(String args[]) {



MyShape s = new MyShape() {
int myv;
public void setValue(int vv) { myv = vv; }
public double area()  { return myv * myv ; }
};

s.setValue(20);
System.out.println(s.area());

}


}

Comments

Popular posts from this blog

Custom Exception example for BankAccount

Annotation

Interface with class and interface as member