java basics about final keyword

2019-03-30 05:19发布

Can final keyword be used for a method?

8条回答
Emotional °昔
2楼-- · 2019-03-30 06:12

Yes, it is possible to declare a method as final. That will mean that a method cannot be overridden by its subclasses.

From The Java Language Specifications, Third Edition, Section 8.4.3.3:

A method can be declared final to prevent subclasses from overriding or hiding it. It is a compile-time error to attempt to override or hide a final method.

For more information, the Writing Final Classes and Methods page from The Java Tutorials has more information.

查看更多
爱情/是我丢掉的垃圾
3楼-- · 2019-03-30 06:17

Sure can. Making it impossible to override.

查看更多
登录 后发表回答