问题描述
我用Google搜索了几次但仍无法理解超类型方法。任何人都可以解释这是什么?
I have googled couple of times but still can't understand the supertype method. Can anyone please explain what is this?
推荐答案
在OOPS中有一个超类型和子类型的概念,在java中这种关系通过继承实现,即使用 extends
关键字:
There is a notion of supertype and subtype in OOPS, In java this kind of relationship is implemented by inheritance i.e. using extends
keyword:
class A {} // super class
class B extends A {} //sub class
任何成员(在超类中声明的字段,方法)将被称为超类型。
Any member (fields, methods) declared in super class is to be called supertype.
因此在上面的上下文中,如果类 A
具有方法如
Therefore in above context if class A
has method like
class A {
void set()
}
Set是类 B的超类型方法
。
但是,请注意,如果有另一个班级说 C
:
However, notice that if there is another class say C
:
class C {
void set()
}
然后 set()
对于 C
类的方法不是超类型,因为没有关系类 A
和类 C
之间的ip(关系由 extends $ c $创建c>关键字,用于继承)。
Then set()
method is not supertype for C
class because there is no relationship between class A
and class C
(relationship is created by extends
keyword, for inheritance).
这篇关于什么是超类型方法?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!