The reason a=2 the first time is because when you create the object ("new") you by default call the constructor. Variables inside the constructor live only for the life of the constructor, then they go bye-bye. Also, the variable "a" in the constructor is not the same as the the instance variable "a". A lot of people use "_a" for instance variable names.
When you passed the number (2), you passed it into the constructor and it set it to "2".
When you did "ob2 = ob1.incrByTen();" the value of ob1.a was already 2, so you added 10 to it and it made it 12. Get it?
Think of how dumb the average person is. Mathematically, half of them are EVEN DUMBER. Smart tiny ad: