英文:
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?
专注分享java语言的经验与见解,让所有开发者获益!
评论