The question is:
interface Animal {
void eat();}
Class Lion implements Animal{
public void eat(){
//do somethng
}
}
class Test {
public static void main(String[] args) {
Animal lion = new Lion();
lion.eat();
lion.eat();
lion.eat();
}
}
The requirement is to calculate how many times the eat method is called without modifying the interface and the class itself.
One way is to extend the lion class and get the results but for every object extending the class we will have to create such classes.
Is there any optimized way to do this.
Publish Subscribe is one way but we don't have the permissions to modify the interface or the Lion class itself.
Aucun commentaire:
Enregistrer un commentaire