1.    写出下列程序的运行结果
public class Cat
{  
  void mi( ) throws NullPointerException
  {
    System.out.println( “Cat mi mi .. “ );
  }
}
public class SmallCat extends Cat
{int i=8;
  void mi( ) throws Exception
  {
    System.out.println( “SmallCat mi mi .. “ );
  }
  public static void main( String[] a ) throws Exception
  {
    Cat cat = new SmallCat();
    cat.mi();
  }
}
写出下列程序的运行结果
interface Playable {
    void play();
}
interface Bounceable {
    void play();
}
interface Rollable extends Playable, Bounceable {
    Ball ball = new Ball("PingPang");
}
class Ball implements Rollable {
    private String name;
    public String getName() {
        return name;
    }
    public Ball(String name) {
        this.name = name;      
    }
   public void play() {
        ball = new Ball("Football");
        System.out.println(ball.getName());
    }
}写出下列程序的运行结果
class Value{
public int i = 15;
}
public class Test{
public static void main(String argv[]){
       Test t = new Test();
    t.first();
   }
public void first(){
       int i = 5;
       Value v = new Value();
      v.i = 25;
      second(v, i);
      System.out.println(v.i);
   }
public void second(Value v, int i){
      i = 0;
       v.i = 20;
     Value val = new Value();
        v = val;
        System.out.println(v.i + " " + i);
      }
}
写出下列程序的运行结果
class MyThread extends Thread{
public void run(){
System.out.println("MyThread: run()");
}
public void start(){
System.out.println("MyThread: start()");
    }
}
class MyRunnable implements Runnable{
public void run(){
System.out.println("MyRunnable: run()");
    }
public void start(){
System.out.println("MyRunnable: start()");
   }
}
public class MyTest {
public static void main(String args[]){
MyThread myThread  =  new MyThread();
MyRunnable myRunnable = new MyRunnable();
Thread thread  =  new Thread(myRunnable);
myThread.start();
thread.start();
}

解决方案 »

  1.   

    第一题:编译失败。重写方法不能抛更大的异常。NullPointerException 是Exception的子类
    第二题:编译失败。接口中的属性是final的。使用final早明的属性不能更改
    第三题:这个题如果对内存里边的数据存放方式了解的话,解决非常简单。我只知道点皮毛都能做出来
    public void first(){ //main方法首先调用这里:
          int i = 5; 
          Value v = new Value(); 
          v.i = 25; 
          second(v, i); //这里回来后,v.i任为20(second里改变了一次),不i=5,因此结果是:15 0 \n 20
          System.out.println(v.i); 
      } 
    public void second(Value v, int i){ 
          i = 0; //i=0,对原来的值无影响。这里执行后,first里的i仍然为5
          v.i = 20; //v.i=20,原来的值也变了,first里的v.i=20
        Value val = new Value(); 
            v = val; //这里v.i=15,,上边的那个v.i不影响。仍为20
            System.out.println(v.i + " " + i); //这里打印15 0
          } 
    结果:
    15 0
    20
    第四题:
    MyThread myThread  =  new MyThread(); //MyThread里重写了start()方法,它的start()不再调用run了
    MyRunnable myRunnable = new MyRunnable(); //这个也是一样
    Thread thread  =  new Thread(myRunnable); //里边调用的是线程Thread里的start()方法,调用run(),而myRunnable的start方法不会执行
    myThread.start(); //打印start()方法里的东西:MyThread: start()
    thread.start(); //打印run()里的东西:MyRunnable: run() 
    结果是:
    MyThread: start()
    MyRunnable: run() 
      

  2.   

    第二题:编译失败。接口中的属性是final的。使用final明的属性不能更改//打错字了555555
      

  3.   

    package demo;public class Cat{
      void mi( ) throws Exception 
      { 
        System.out.println("Cat mi mi .. " ); 
      } 
      
    } package demo;public class SmallCat extends Cat 
    {int i=8; 
      void mi( ) throws Exception 
      { 
        System.out.println( "SmallCat mi mi .. "); 
      } 
      public static void main( String[] a ) throws Exception 
      { 
        Cat cat = new SmallCat(); 
        cat.mi(); 
      } 

     -----结果
    SmallCat mi mi .. 
      

  4.   


    public class MyRunnable implements Runnable{ 
    public void run(){ 
    System.out.println("MyRunnable: run()"); 
        } 
    public void start(){ 
    System.out.println("MyRunnable: start()"); 
      } 
    } class MyThread extends Thread{ 
    public void run(){ 
    System.out.println("MyThread: run()"); 

    public void start(){ 
    System.out.println("MyThread: start()"); 
        } 

    public  class MyTest { 
    public static void main(String args[]){ 
    MyThread myThread  =  new MyThread(); 
    MyRunnable myRunnable = new MyRunnable(); 
    Thread thread  =  new Thread(myRunnable); 
    myThread.start(); 
    thread.start(); 


    ---结果MyThread: start()
    MyRunnable: run()