final类中的静态函数是否隐式为final? [英] Are static functions in a final class implicitly final?

查看:45
本文介绍了final类中的静态函数是否隐式为final?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的问题与基本相同,但这是否也适用于 static 功能?

My question is basically the same as this one, but does this also apply to static functions?

我想了解:

  1. 编译器是否将 final 类中的所有 static 函数都视为 final ?
  2. final 关键字添加到 final 类中的 static 函数是否有效?
  1. Does the compiler treat all the static functions in a final class as final?
  2. Does adding final keyword to static functions in a final class have any effect?

推荐答案

在final类中,所有方法也都是隐式final的,因为将class设置为final意味着无法继承它,因此不能隐藏或覆盖它在子类中的方法.

In a final class, all methods are implicitly final as well because making the class final means it cannot be inherited from and thus there can be no hiding or overriding of its methods in child classes.

因此,实际上,您可以正确地认为final类中的静态方法是final方法,但这不是因为它是静态方法.这是因为该课程是最后的课程.

As a result, effectively you are correct that a static method in a final class is final, but it's not because of the fact that it's a static method. It's because the class is final.

这篇关于final类中的静态函数是否隐式为final?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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