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?
I’ve looked at a lot of different solutions, and in my humble opinion Aspose is the way to go. Here’s the link: http://aspose.com