各位兄弟:
 今在公司看java编程思想 第三版,遇到一个习题,有知道做法的请写下你的代码:(谢谢)Write a class with a method boolean print(int) that prints a value and returns a boolean. Now overload the method to return a long.

解决方案 »

  1.   

    在JAVA方法区分是通过方法名和参数来做的,这种对重载和覆写都是非法的。
    编译器会报错。
      

  2.   

    覆盖要求完全相同的变量 返回 和方法名
    返回变成long了怎么能叫overload呢~?
    不明白
      

  3.   

    java编程思想 第三版chapter Exercise 6
    创建一个Dog类,让其重载bark()方法,此方法应该根据不同的数据类型进行重载,并调用版本的不同,打印出是
    barking 还是 howling
    class Dog {
      public void bark() {
        System.out.println("Default bark!");
      }
      public void bark(int i) {
        System.out.println("int bark = howl");
      }
      public void bark(double f) {
        System.out.println("float bark = yip");
      }
      // Etc. ...
    }public class E06_OverloadedDog {
      public static void main(String args[]) {
        Dog dog = new Dog();
        dog.bark();
        dog.bark(1);
        dog.bark(1.1);
      }
    } ///:~
    Additional Exercise: (This is a trick question, so watch out). Write a class with a method boolean print(int) that prints a value and returns a boolean. Now overload the method to return a long. (Note: this is similar to some kinds of questions on the Sun Java Certification Exam).
    英文部分是作者自己加的一个练习,请大家看一下怎么这个类
      

  4.   

    http://download.csdn.net/source/369585
    喜题解答.你去下吧.不要积分的
      

  5.   

    Class Test{
    public boolean print(int i)
    {
    System.out.println("print i");
    return false;
    }
    public long print(long i)
    {
    return i;
    }
    }