这OO概念"基地B =新派生的()"的例子吗? [英] Which OO concept is "Base b = new Derived()" an example of?

查看:95
本文介绍了这OO概念"基地B =新派生的()"的例子吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

结果
我经过一个测试,遇到一个问题中,我们没有找到与同事的协议。



С++

  1 Base类{}; 
2类派生的:公共基础{};
3类Foo
4 {
5公众:
6美孚()
7 {
-8-基* B =新派生的(); //概念的名字是?
9}
10};



C#



  1抽象类基地{} 
2公共类派生:基{}
3
4个公共类Foo
5 {
6公众美孚
7 {
-8-基b =新派生的(); //概念的名字是?
9}
10}



现在的问题是:上面的行数8以下OO概念




  1. 多态性

  2. 汇聚

  3. 的例子
  4. 封装

  5. 抽象

  6. 继承



请把与答案知识的来源的链接。



PS该测试是在breinbenchOO概念。它是免费的。



更新:结果



从一答案它捍卫的多态性




简单来说,多态性是一种类型的
的能力, A,显示为
和像其他类型的使用,B.在
强类型语言中,这通常
表示A型莫名其妙地从b
类或A类派生实现了代表b型的
接口。




从它捍卫维基百科的继承




继承有时也被称为
概括,因为在是-A
的关系表示对象的类之间的层次






$因此,b $ b

继承了另一个
视图,双,称为多态,
,它描述的代码
多件由共同控制
代码来控制。




所以基础=新派生的()显示是(继承)。而这个结果就是多态性



所以我怀疑什么是正确的?


解决方案

这个问题很简单...是的多态性



多态行为是因为继承的实现。中衍生的基地,因为离碱的继承,你可以把实例。这是多态的定义,当一个面向对象的语言适用于各类...



http://en.wikipedia.org/wiki/Polymorphism_(computer_science)



[更新,更新]



我希望这是不够明确......这些都是说同样的事情的所有不同的方式。



多态性(C#编程指南)




通过继承,一个类可以作为超过
一种类型的;它可以是用作其自己的类型,任何碱的类型,
或任何接口类型
如果它实现
接口这叫做
多态性


[更新]



由于意见,我会尝试更加具体的......我不是说因为碱的继承了该行的多态行为的一个例子,我说一个实例的一个类型,它派生自的变量赋值就是一个例子的多态行为。引用我附上链接的第一句话...




在计算机科学中,多态性是
A编程语言的功能,
允许不同的数据类型
的值,使用统一的
接口




含义处理我可以治疗的推导基地的实例表现出多态实例。这不依赖于对类虚拟方法的存在是真实



和从不同的源 ...




简单来说,多态性是显示为
和像另一个类型被用于一种类型中,A,的
能力,B.在
强类型语言中,这通常
意味着A型莫名其妙地从b
类派生,或A型实现了代表b型的
接口。




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

  1. Polymorphism
  2. Aggregation
  3. Encapsulation
  4. Abstraction
  5. 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?

解决方案

This question is easy... It is Polymorphism.

The Polymorphic behavior is accomplished because of inheritance. You can treat the instance of Derived as Base because Derived inherits from Base. This is the definition of Polymorphism when applied to types in an OO language...

http://en.wikipedia.org/wiki/Polymorphism_(computer_science)

[Update, Update]

I hope this is definitive enough... these are all different ways of saying the same thing.

Polymorphism (C# Programming Guide)

"Through inheritance, a class can be used as more than one type; it can be used as its own type, any base types, or any interface type if it implements interfaces. This is called polymorphism."

[Update]

Given the comments I will try to be more specific... I am not saying that because Derived inherits from Base that the line is an example of Polymorphic behavior, I am saying that the assignment of an instance to a variable of a type that it derives from is an example of Polymorphic behavior. To quote the first sentence of the link I attached...

"In computer science, polymorphism is a programming language feature that allows values of different data types to be handled using a uniform interface"

Meaning that I can treat an instance of Derived as an instance of Base is exhibiting a Polymorphic behavior. This doesn't depend on the existence of virtual methods on the class to be true.

and another quote from a different source...

"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."

这篇关于这OO概念"基地B =新派生的()"的例子吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆