当前位置: 技术问答>java相关
?????有兴趣看看这个问题??????????????
来源: 互联网 发布时间:2015-08-22
本文导语: Which of the following statements are true? 1) Methods cannot be overriden to be more private 2) Static methods cannot be overloaded 3) Private methods cannot be overloaded 4) An overloaded method cannot throw exceptions not checked in the base c...
Which of the following statements are true?
1) Methods cannot be overriden to be more private
2) Static methods cannot be overloaded
3) Private methods cannot be overloaded
4) An overloaded method cannot throw exceptions not checked in the base class
说明理由!
1) Methods cannot be overriden to be more private
2) Static methods cannot be overloaded
3) Private methods cannot be overloaded
4) An overloaded method cannot throw exceptions not checked in the base class
说明理由!
|
过载和重载都是 Java 多态性的体现。过载多用于构造函数。看看 JAVA的源码程序,那里面有很多的过载。举个例子,我随便写的:
public class FileInputStream extends InputStream{
File file = null;
//下面两个方法名一样,称为过载,这种构造函数过载是为了我们传参数的随意性,方便
public FileInputStream(File file){
this.file = file;
}
public FileInputStream(String filePath){
file= new File(filePath);
}
}
public class FileInputStream extends InputStream{
File file = null;
//下面两个方法名一样,称为过载,这种构造函数过载是为了我们传参数的随意性,方便
public FileInputStream(File file){
this.file = file;
}
public FileInputStream(String filePath){
file= new File(filePath);
}
}
|
int run() 好像应该是void run() 吧。
|
哦,是我弄错了,
3)也是错误的,静态方法也是能重载的,是覆盖不起作用。
所以这道题应该是没有正确答案的,要不你那出来正确答案我们研究一下。
3)也是错误的,静态方法也是能重载的,是覆盖不起作用。
所以这道题应该是没有正确答案的,要不你那出来正确答案我们研究一下。
|
第一个是不对,我做测试了,私有方法是可以覆盖的。