class A
{
   void fun(int a){...}
   void fun(int a,int b){....}
}
这样算多态吗???

解决方案 »

  1.   

    不算.
    这是overloading
    不过也有人定义了方法多态的概念,只是感觉很无聊.
      

  2.   

    No, this is overloading, which means the same method name and the same return type, but different parameters.
      

  3.   

    如果你定义的是一个虚类,那应该就是吧,我半捅水也不太清楚。但我所知的多态应该是通过java提供的接口来实现,而接口是通过虚类来实现。
      

  4.   

    thinking in java 里多态主要还是指”向上转型“ 和 运行时的动态绑定.
    具体三言两语我也说不清楚,写个例子说明就最好不过了
      

  5.   

    I have IDE in company, so there may be some mistakes.
    class Father{
       void print(){
          System.out.println("I am Father!");
       }
    }class Son extends Father{
       void print(){
          System.out.println("I am Son!");
       }
    }public class Testing{
       public static void main(String args[]){
          Father f = new Son();
          f.print();
       }
    }
      

  6.   

    数据抽象、继承和多态是面向对象程序设计语言的三大特性。多态,我觉得它的作用就是用来将接口和实现分离开,改善代码的组织结构,增强代码的可读性。在某些很简单的情况下,或许我们不使用多态也能开发出满足我们需要的程序,但大多数情况,如果没有多态,就会觉得代码极其难以维护。 在Java中,谈论多态就是在讨论方法调用的绑定,绑定就是将一个方法调用同一个方法主体关联起来。在C语言中,方法(在C中称为函数)的绑定是由编译器来实现的,在英文中称为early binding(前期绑定),因此,大家自然就会想到相对应的late binding(后期绑定),这在Java中通常叫做run-time binding(运行时绑定),我个人觉得这样称呼更贴切,运行时绑定的目的就是在代码运行的时候能够判断对象的类型。通过一个简单的例子说明: /** * 定义一个基类 */ public Class Parents {     public void print() {         System.out.println(“parents”);     } } /** * 定义两个派生类 */ public Class Father extends Parents {     public void print() {         System.out.println(“father”);     } } public Class Mother extends Parents {     public void print() {         System.out.println(“mother”);     } } /** * 测试输出结果的类 */ public Class Test {     public void find(Parents p) {         p.print();     }     public static void main(String[] args) {         Test t = new Test();         Father f = new Father();         Mother m = new Mother();         t.find(f);         t.find(m);     } } 最后的输出结果分别是father和mother,将派生类的引用传给基类的引用,然后调用重写方法,基类的引用之所以能够找到应该调用那个派生类的方法,就是因为程序在运行时进行了绑定。 
      

  7.   

    是重载(overloading)
    多态是通过覆盖父类的方法来实现,在运行时根据传递的对象引用,来实现相应的方法。
    public class Animal{};
    public class Fish extends Animal{};
    Animal a= new Fish();
    Fish f =(Fish)a;
      

  8.   

    1有继承
    2有重写
    3有父类引用指向子类对象
    class Father{
       void print(){
          System.out.println("I am Father!");
       }
    }class Son extends Father{
       void print(){
          System.out.println("I am Son!");
       }
    }public class Testing{
       public static void main(String args[]){
          Father f = new Son();
          f.print();
       }
    }