locked
Inheritance and problems RRS feed

  • Question

  • User-147723199 posted

    HI, I have created a master class with 2 classes inheriting and overriding a method of the base class. In my main program I read some data and put them in an array"inputArray". I use a write only property (or tried constructor) to assign this input array to protected array "A" in my class (so A=inpuArray). I do some sorting in this A array in my Class and use another property to return the sorted array (... public SortedArray { return A;}). In my 2 other subclasses I want to pass again the inputArray to do some sorting with different method.

    The problem is that after running the sort method of my base class, the inputArray in my main program is changed also and is sorted, so I can not feed it again it without setting again its value. Shouldn't this array remain unchanged as it is declared outsde of the classes and no manipulating is done on it?

    Sunday, May 25, 2014 4:30 AM

Answers

  • User465171450 posted

    Not sure how the application flow is, but when you say "declared outside of the classes" isn't exactly correct. Your base class is part of each of these classes. When you say this, it is like saying your bedroom is declared outside the house. It really isn't. Your base class is the foundation of your other classes and in any instance of your child class, anything that is in the base class is part of them not outside them. 

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Sunday, May 25, 2014 11:34 AM