最终声明方法和类 [英] Declaring Methods and classes final

查看:90
本文介绍了最终声明方法和类的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有人可以向我解释一下这种用途的冒险是什么吗?

我试图了解太阳在教程上发布的内容但他们没有解释那么多


Plz帮助!

can some one explain to me what are the adventages of such use?
I tried to understand what sun is posting on the tutorial but they don''t explain that much

Plz help!

推荐答案


有人可以向我解释一下什么是冒险这样的使用?

我试着了解太阳在教程上发布了什么,但是他们没有解释那么多


Plz帮助!
can some one explain to me what are the adventages of such use?
I tried to understand what sun is posting on the tutorial but they don''t explain that much

Plz help!



假设我上了课,我不希望任何人在

扩展课程中覆盖一个方法;我可以让这个方法最终。假设我不希望任何人从我的课堂上扩展他们的班级。我可以让整个班级最终完成。


亲切的问候,


Jos

Suppose I''ve made a class and I don''t want anyone to override a method in an
extending class; I can make that method final. Suppose I don''t want anyone to
extend their class from my class; I can make that entire class final.

kind regards,

Jos


在java中他们说过教程网站:

"从构造函数调用的方法通常应该被声明为final。如果构造函数调用非final方法,则子类可能会以令人惊讶或不合需要的结果重新定义该方法。

为什么从constractors调用的方法?
in the java tutorial site they stated:
"Methods called from constructors should generally be declared final. If a constructor calls a non-final method, a subclass may redefine that method with surprising or undesirable results."
why methods called from constractors??



为什么从constractors调用的方法?
why methods called from constractors??

展开 | 选择 < span class =codeDivider> | Wrap | 行号


这篇关于最终声明方法和类的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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