Professional Documents
Culture Documents
classTestAnnonymousInner{
publicstaticvoidmain(Stringargs[]){
Personp=newPerson(){
voideat(){System.out.println("nicefruits");}
};
p.eat();
}
}
Compile by: javac TestAnnonymousInner.java
Run by: java TestAnnonymousInner
Output: nice fruits
importjava.io.PrintStream;
staticclassEmp$1extendsPerson
{
Emp$1(){}
voideat()
{
System.out.println("nicefruits");
}
}
interfaceEatable{
voideat();
}
classTestAnnonymousInner1{
publicstaticvoidmain(Stringargs[]){
Eatablee=newEatable(){
publicvoideat(){System.out.println("nicefruits");}
};
e.eat();
}
}
staticclassInner{
voidmsg(){System.out.println("datais"+data);}
}
publicstaticvoidmain(Stringargs[]){
TestOuter1.Innerobj=newTestOuter1.Inner();
obj.msg();
}
}
Proxy
The Proxy is one of the most common
design patterns in circulation. Gamma et.
al. define the intent of the Proxy as:
"Provide a surrogate or a placeholder for
another object to control access to it." The
basic idea is that a class substitutes for
another class. In other words, a Proxy
class provides an interface that reflects
the interface of the class that it is
substituting. In Java, a Proxy class must
implement the same interface as the class
that it is substituting.