c++虚函数的意义在于实现多态性,java与之对应的是接口interface。

解决方案 »

  1.   


    java没有虚函数这一说法,不过可以这样来看,
    1。java里的所有方法都对应c++的虚函数;
    2。java里的所有抽象方法和接口方法对应c++的纯虚函数;
      

  2.   

    虚函数是指:一个类的method的属性,         如
             class father{
                        'vertual' void getname{system.out.println("father");}
             }
             class son extend father{
                         'vertual' void getname{system.out.println("son");}
             }         main(){
                     son theSon = new son();
                     father theFather = son;
                     father.getname();
                     son.getname();
             }
    如果是虚函数应该的结果是:
             father
             son
    但是java中结果会是
             son
             son
    我试了interface也是这样,不知道是我弄得不对还是怎么?
      

  3.   

    有但不是一对一的关系
    abstreact
    interface
    是有区别
      

  4.   

    abstract class C{
      abstract void func();
    }
      

  5.   

    哎,真的假的?abstract 的类能实例化出一个对象吗?
      

  6.   

    Yes, you can create an abstract method in a class which can be implemented in the subclass. This mechanism is the counterpart of pure virtual function in C++.
      

  7.   

    但是能实现需要的结果吗?abstract的那个函数调用了会显示出father吗?等待ing