You can use getters & setters to access that variable.
Joseph yan
Greenhorn
Joined: Mar 02, 2009
Posts: 3
posted
0
Thanks for your replies ..
How do i do with getter and setter ?
Can you please provide some example .
Please note only problem is i dont want to break encapsulation.
if i will use protected then varible is visible out side the class.
John de Michele
Rancher
Joined: Mar 09, 2009
Posts: 600
posted
0
Joseph:
You probably just want a getter. Just move your getPrice() method from class A to class B. Extending classes already breaks encapsulation. If encapsulation is what you are concerned about, you should probably use composition rather than inheritance.
John.
Campbell Ritchie
Sheriff
Joined: Oct 13, 2005
Posts: 32694
4
posted
0
Joseph yan wrote:How do i do with getter and setter ?
Can you please provide some example .
Paul Sturrock has provided an excellent example which maintains encapsulation.