I use C #, but I think this is a pretty general OO question. Suppose I have a class called Animal, and it has properties like LegCount, EyeCount, HasFur, EatsMeat, etc.
Let's say I have an instance of a Animal. Suppose a has a LegCount of 4 and an EyeCount of 2.
Now I would like to create an instance d type Dog, which inherits from Animal. I would like to initialize d with all values of a . I understand that I could create a constructor or some other method that Animal will take and spit out a new Dog with all the values copied to, but I was hoping there was some kind of object-oriented principle / trick that engulfed me.
What I want to do in plain English:
Create a new instance of d for Dog, with all initial values from a . The key is "all", as opposed to specifying each property individually.
When you create a class that inherits from some other class, you do not need to list all its inherited elements. He simply inherits them all. So I'm wondering if I can inherit values in real instances.
Chris source share