Hi,all
The following description:
A final method cannot be overridden in a subclass. This is discussed in the lesson on interfaces and inheritance. Here is an example of using a final method for initializing an instance variable: class Whatever {
private varType myVar = initializeInstanceVariable();
protected final varType initializeInstanceVariable() { //initialization code goes here
}
}
This is especially useful if subclasses might want to reuse the initialization method. The method is final because calling non-final methods during instance initialization can cause problems.-And my questions as follows:
1.Since the final method cannot be overridden, how to reuse.
2.Why choose final method, what can we benefit from final method.
3.I will try whether it's OK when I use a non-final method to initialization.Best wishes.
The following description:
A final method cannot be overridden in a subclass. This is discussed in the lesson on interfaces and inheritance. Here is an example of using a final method for initializing an instance variable: class Whatever {
private varType myVar = initializeInstanceVariable();
protected final varType initializeInstanceVariable() { //initialization code goes here
}
}
This is especially useful if subclasses might want to reuse the initialization method. The method is final because calling non-final methods during instance initialization can cause problems.-And my questions as follows:
1.Since the final method cannot be overridden, how to reuse.
2.Why choose final method, what can we benefit from final method.
3.I will try whether it's OK when I use a non-final method to initialization.Best wishes.
解决方案 »
- 求一段js,我页面上显示一个图片的名字,aaa.jpg,我鼠标移到aaa.jpg文字上就弹出一个框来显示这张图,鼠标移走就消失,哪位高手有给我下,谢了
- Hibernate 日期检索问题
- 如何在java中启动本地程序?
- 请教大家一个基础问题
- [求助]关于File路径的问题
- 求教:ibatis中sqlmap中建立一个有特殊需要insert方法?急!!
- 经理都搞不懂的问题,请教(附简单代码)
- 小问题,如何把这个APPLET改写成APPLICATION?
- 高分求代码!!!!
- 有没有人装过JRUN STUDIO?其中的问题。。。。。
- (int)(char)(byte)-1具体是怎么换算的?
- 关于图片是否保存至数据库的问题
2,3.父类初始化时调用子类的方法是很不好的,具体看effective java
1. Not all method are intended to be reuse。 If the function of a method is just to fullfill tasks available by its class only,why the subclass will reuse it?
2. a. More clear method group.
b.encapsulated reason.
3. I don't know what's your meaning