This shows you the differences between two versions of the page.
Both sides previous revisionPrevious revisionNext revision | Previous revision | ||
notes:cprog:fall2021:projects:oop1 [2021/11/04 02:57] – [Parent-Child Relationships] ehauber1 | notes:cprog:fall2021:projects:oop1 [2021/11/05 04:01] (current) – [References] hhemler | ||
---|---|---|---|
Line 78: | Line 78: | ||
Since the Child simply inherits the properties of the Parent, one Parent can have multiple Children. | Since the Child simply inherits the properties of the Parent, one Parent can have multiple Children. | ||
Two Children of the same Parent will also have no direct relationship. | Two Children of the same Parent will also have no direct relationship. | ||
- | Children can themselves have Children that inherit from them, creating large inheritance chains. | + | Children can themselves have Children that inherit from them, creating large inheritance chains. |
+ | Children can also multi-inherit, | ||
Parent/ | Parent/ | ||
- | Each Child and Parent can have multiples of the others. A Child can multi-inherit, and a Parent | + | It’s also possible to inherit from a class that is itself derived from another class |
+ | ====A reflection on the concept of inheritance==== | ||
+ | (among other things) | ||
+ | |||
+ | It is easier to understand inheritance than it is most concepts in programming, | ||
+ | |||
+ | Something Interesting to note is that child class cannot access the private information relating to their parents, but can still have them. For example, if plant(as a parent class of tree) has a private int of age, then tree will also have a private value of age. This is because when inheritance is activated it calls upon the parent' | ||
+ | |||
+ | When something has multiple | ||
+ | |||
+ | Inheritance allows us to reuse classes by having other classes inherit their members. | ||
+ | |||
+ | It is possible to make a class non-subclassable (sterile) in C++ with the " | ||
+ | |||
+ | COOL BUG FACT: Inheritance was first created for the Simula programming languages | ||
=====Program===== | =====Program===== | ||
Write a program that creates a parent-child class structure. It can be anything, so long as you genuinely implement it and it works. A few possible examples for inspiration: | Write a program that creates a parent-child class structure. It can be anything, so long as you genuinely implement it and it works. A few possible examples for inspiration: | ||
Line 97: | Line 112: | ||
* https:// | * https:// | ||
* https:// | * https:// | ||
- | * https:// | ||
* https:// | * https:// | ||
* https:// | * https:// |