"java則不會"
哪来得结论??

解决方案 »

  1.   

    他的用意是实现---多态---因为java所有的方法都是动态绑定(fianl出外),而c++则是通过虚函数实现的,you know
      

  2.   

    to  bdsc() 
    這是我試過的﹐你不信試試to  0flying0(j2ee的狂热分子)我說的同名方法不是虛函數的那種﹐是指在子類和父類中參數不同的那種同名方法
      

  3.   

    c++隱藏代碼//: C14:NameHiding.cpp
    // From Thinking in C++, 2nd Edition
    // Available at http://www.BruceEckel.com
    // (c) Bruce Eckel 2000
    // Copyright notice in Copyright.txt
    // Hiding overloaded names during inheritance
    #include <iostream>
    #include <string>
    using namespace std;class Base {
    public:
      int f() const { 
        cout << "Base::f()\n"; 
        return 1; 
      }
      int f(string) const { return 1; }
      void g() {}
    };class Derived1 : public Base {
    public:
      void g() const {}
    };class Derived2 : public Base {
    public:
      // Redefinition:
      int f() const { 
        cout << "Derived2::f()\n"; 
        return 2;
      }
    };class Derived3 : public Base {
    public:
      // Change return type:
      void f() const { cout << "Derived3::f()\n"; }
    };class Derived4 : public Base {
    public:
      // Change argument list:
      int f(int) const { 
        cout << "Derived4::f()\n"; 
        return 4; 
      }
    };int main() {
      string s("hello");
      Derived1 d1;
      int x = d1.f();
      d1.f(s);
      Derived2 d2;
      x = d2.f();
    //!  d2.f(s); // string version hidden
      Derived3 d3;
    //!  x = d3.f(); // return int version hidden
      Derived4 d4;
    //!  x = d4.f(); // f() version hidden
      x = d4.f(1);
    } ///:~
    java 名字隱藏代碼
    package e20040621;
    public class a{
         public void method(){
               System.out.println("a.method()");
         }
     }
     
     package e20040621;
     public class b extends a{
          public void method(int i){
                System.out.println("b.method()");
          }
     }
     
     package e20040621;
     public class methodtest{
          public static void main(String args[]){
                b bmethod=new b();
         bmethod.method();   //不會隱藏父類的 method();
         bmethod.method(3);
          }
     }
      

  4.   

    不好意思 ﹐表達上有問題﹐我說的就是上面代碼的意思﹐你們說java有很多繼承c++的東西﹐
    這個為什么不
      

  5.   

    c++你可以自己控制一切,所以你要负更多的责任。如上例你声明称virtual就合java一样了。"你們說java有很多繼承c++的東西﹐這個為什么不"
    因为java语言的设计不想让java像c++一样的复杂,而使得只有聪明的人才能掌握
      

  6.   

    在c++里﹐子類繼承父類時﹐子類如果有和父類同名的方法﹐那么它會把父類的同名方法覆蓋掉﹐java則不會﹐為什么java不覆蓋﹐它的用意是什么
    -----------------------------------
    在c++和java中子類如果有和父類相同的方法(指方法名和参数类型、个数都完全相同)那么它们都会會把父類的相同方法覆蓋掉
      

  7.   

    不要用c的知识来解释java,虽然语言可以借鉴学习但毕竟是不同的语言。
    都是面向对象的语言,都能实现覆盖。