这是一个新手问题.我读到JVM的执行是从层次结构中从最低级别搜索methodname开始的,如果该方法在该类中不可用,则它将遍历到查找该方法的父类.
如果是这种情况那么为什么我们需要使用"@override"将自定义逻辑添加到继承的类中?
下面的例子说明了我的问题
class superclassA
{
method()
{
}
}
class subclassB extends superclassA
{
@Override
//While executing if JVM starts looking for the method name from the lowest hierarchy
//then why do we have to use "override" as the methodname will be matched from the lowest level itself?
method()
{
--custom subclass specific code...
}
}
Run Code Online (Sandbox Code Playgroud)
如果是这种情况那么为什么我们需要使用"@override"将自定义逻辑添加到继承的类中?
我们没有.该@Override注解没有技术含义-它存在于文件的事实,此方法将覆盖一个超类,它具有一定的优势: