Hi Guys,
I was passing a test and met a question in which we didn't find an agreement with my colleagues.
С++
1 class Base {};
2 class Derived : public Base {};
3 class Foo
4 {
5 public:
6 Foo()
7 {
-8- Base* b = new Derived(); // Concept name is?
9 }
10 };
C#
1 abstract class Base{}
2 public class Derived : Base{}
3
4 public class Foo
5 {
6 public Foo
7 {
-8- Base b = new Derived(); // Concept name is?
9 }
10 }
The question is: line number 8 above is an example of the following oo concept
- Polymorphism
- Aggregation
- Encapsulation
- Abstraction
- Inheritance
Please put a link with the answer to the source of knowledge.
P.S. The test is 'OO Concept' on breinbench. It is free.
Update:
From one of the answer which defends polymorphism
"In simple terms, polymorphism is the ability of one type, A, to appear as and be used like another type, B. In strongly typed languages, this usually means that type A somehow derives from type B, or type A implements an interface that represents type B."
From wikipedia which defends inheritance
Inheritance is also sometimes called generalization, because the is-a relationships represent a hierarchy between classes of objects.
and
Inheritance therefore has another view, a dual, called polymorphism, which describes many pieces of code being controlled by shared control code.
so Base = new Derived()
shows 'is a'(inheritance). And consequence of this is polymorphism.
So I doubt what is right?