In class "A" I had declared an instance variable i and in methodOne I am declaring a local variable i and initializing it to some value. I need that value in methodThree but I have to go through methodTwo(even if I am not doing any processing with that variable) and I am calling methodThree from methodTwo.
Is it a good coding practice to do like this (or) to declare the variable i as an instance variable and use it in the program. I heard when we go for a instance variable, each time the instance variable is used in the program it adds overhead to the object and results in time cost.
Originally posted by vishnu prakash: [CODE] [...] I heard when we go for a instance variable, each time the instance variable is used in the program it adds overhead to the object and results in time cost.
In 99.99% of all cases, the time cost (if any) will be irrelevant. You should decide on this based on other reasons than performance, for example flexibility and maintainability of the design.
The soul is dyed the color of its thoughts. Think only on those things that are in line with your principles and can bear the light of day. The content of your character is your choice. Day by day, what you do is who you become. Your integrity is your destiny - it is the light that guides your way. - Heraclitus