[List of FAQs] | [Android FAQ] | [Samuh Varta]
ben oliver wrote:In class A, attributes "name" and "address" are all "private", so they are not supposed to be accessible in class B. But are they still inherited by class B ? i.e. Does an object of B have varibles of "name" and "address" ? If yes, what does it mean that you can inherite variables but they are not accessible to you ?
ben oliver wrote:This means it is object "b" who calls inherited "setName" method, and you can see, when I do "this.name = name", it sets "b"'s name field, so object b can acces "name" !!
Vishal Pandya wrote:Ok. Let me try,
For Object reference b , "name" is not accessible, but for setName() methods is accessible, and for setName() , "name" is accessible. Hence, b can access "name".
You down with OOP? Yeah you know me!
[List of FAQs] | [Android FAQ] | [Samuh Varta]
ben oliver wrote: Now, couple questions --
1. when I do new B(), certainly I created an instance of class B in memory. Do I also create a specific instance of class A in memory ???
If you have created object of class B then obviously it will set for object b only. Now don't say that it is private and how come it accessible in class B. It is accessible through getters/setters.ben oliver wrote:do I set this variable value for object b ? or do I actually set this variable value for an object of class A ?? Which object does this "name" belong to exactly ??
ben oliver wrote: Now, couple questions --
1. when I do new B(), certainly I created an instance of class B in memory. Do I also create a specific instance of class A in memory ???
2. "name" is an instance varibale, when I do
b.setName("john");
b.getName();
to set the value for "name" field, do I set this variable value for object b ? or do I actually set this variable value for an object of class A ?? Which object does this "name" belong to exactly ??
[List of FAQs] | [Android FAQ] | [Samuh Varta]