I came across one method which i couldn't understand.
1. Line number 5, a method add()
is called through object prx
and then it continues to define this method. Which concept is this?
2. Line 7. Here as method is overidden within method definition. As per my knowledge method can not be defined within method but in this example method addResp()
(#7) is defined within prx.add()
(#5) and this is defined in IntCall()
. (#1) Then how it is possible here?
What concept should i study to understand above code?
1 public void IntCall() throws Exception {
2 NmbrCalc addres = new NmbrCalc();
3 for (int i = 0; i < 20; ++i) {
4 int v1 = i/50;
5 prx.add(v1, 200, new IListenResponse() {
6 @Override
7 public void addResp(int result) {
8 addres.setValue(result);
9 }
10 });
11 }
12 }