-1

Suppose I have:

class A and class B

Class B inherits from class A his methods. With an instance of B I wanna to call a method of class A but I wanna that the method of class A reads and stores data directly in the calling instance of class B (in a property of class B) Cannot figure out how to achieve this.

Claudio Ferraro
  • 4,551
  • 6
  • 43
  • 78

1 Answers1

1

Class B derive from Class A, so when you instanciate and object of class B, you create and object of class A completed by and object of class B.

B b = new B()

&b points to b, but also to the parent object a (in fact it points to an object A, completed by an object B). So when you call b.Amethod(), if it modify A.Amember, it will of course modify b.Amember, because they are the same variable for instance b.

Fabrice Jammes
  • 2,275
  • 1
  • 26
  • 39