为什么我要使用扩展而不是实例,反之亦然?

huangapple 未分类评论48阅读模式
英文:

Why would I use extension over an instance and vice versa?

问题

我是Java的新手,正在学习类关键字。我已经看了一些有限的例子,但我正在努力理解为什么会选择使用实例对象而不是扩展对象。在我看过的教程中,有一个"book"类,而"magazine"是"book"类的一个实例。但如果这个类是抽象的,那么你就不能有一个实例,只能有一个扩展。为什么我会选择扩展而不是实例,反之亦然?有人能提供一个在何时使用其中之一更好的示例吗?

英文:

I am new to Java and am learning class keywords. I have been given limited examples, but I am trying to understand the reasons why you would use an instance object over extending an object. In the tutorials I have seen there is a book class and a magazine is an instance of book. But if the class is abstract then you cannot have an instance only an extension. Why would I use extension over an instance and vice versa? Can anyone provide an example of when it would be better to use one over the other?

huangapple
  • 本文由 发表于 2020年5月30日 07:05:59
  • 转载请务必保留本文链接:https://java.coder-hub.com/62095821.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定