还有这个问题:
What will happen when you attempt to compile and run the following code?. class Background implements Runnable{
int i=0;
public int run(){
 while(true){
 i++;
 System.out.println("i="+i);
 } //End while
     return 1;
 }//End run}//End class
1) It will compile and the run method will print out the increasing value of i. 
2) It will compile and calling start will print out the increasing value of i. 
3) The code will cause an error at compile time. 
4) Compilation will cause an error because while cannot take a parameter of true. 给出理由,顺便测试一下您对java基础的掌握知识

解决方案 »

  1.   

    int run() 好像应该是void run() 吧。
      

  2.   

    私有方法如果可以覆盖那么覆盖的意义和结果是什么呢??
    http://java.sun.com/docs/books/tutorial/java/javaOO/override.html 
    参考一下,give me a correct answer!thanks楼上的兄弟好象不感肯定啊!
      

  3.   

    1) Methods cannot be overriden to be more private仔细看一下这句话的含义,不是“私有方法不能被重载”。而是“重载的方法不能降低它的访问级别”,这句话当然是没有问题的。至于私有方法重载的意义,也不要太考究,跟非私有的方法重载没有本质的区别,只是一个访问级别不一样而已。
    :-]
      

  4.   

    其实这道题很简单,主要是讲 overriden(重载)和 overloaded(过载)的区分。过载基本上没有什么限制,所以2)3)4)都是废话。而1)讲的是重载,要小心哦。:->
      

  5.   

    过载什么时候能派上用场呢???for example!
      

  6.   

    过载和重载都是 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);
      }
    }
      

  7.   

    第二个问题的答案是:3。因为return 1;这个句子无法到达。
    重申一下,第一个问题的答案是:1,4。
      

  8.   

    第二个问题的答案是:3 正确,但原因是:
    The error is caused because run should have a void not an int return type.