I couldn't understand the answer in a previous

thread , so I am posting it as a new topic.(Please dont refer me to the old thread again)

What will be the result of the following code?

1. class Base {

2. int i;

3. Base(){

4. add(1);

5. }

6. void add(int v){

7. i+=v;

8.

9. }

10. void print(){

11. System.out.println(i);

12. }

13. }

14.

15. class Extension extends Base{

16. Extension(){

17. add(2);

18. }

19. void add(int v){

20. i+=v*2;

21.

22. }

23. }

24.

25. public class Test6{

26.

27. public static void main(

String[] args){

28. bogo(new Extension());

29.

30. }

31. static void bogo(Base b){

32. b.add(8);

33. b.print();

34.

35. }

}

In the example seen above, if Base() is called when Extension is instantiated, then add(1) would result in 1, since

int i is not intialised in Base it has 0;

then add(2) would yield :1+2*2=5;

then b.add(8) would be 5+8*2=21.

Can anybody explain it to me. The answer when I compile is 22.

The explanation above was not clear to me how i=2;

Call me stupid but I need to know..

Thanks