1返回与父类完全相同的方法名,返回值和参数列表,才会覆盖
public void mothodTwo(){}
public static void mothodThree(){}
2。我只知道有属性的隐藏,也就是同名的属性变量

解决方案 »

  1.   

    in class B :public static void mothodThree(){}
    称为隐藏 或叫做 hidden public void mothodTwo(){}
    叫做覆盖public static void mothodOne(){}
    public void mothodFour(){}
    编译更本不会通过  static 方法和实例方法之间不能互相覆盖隐藏 是专门针对 static 方法而言的
    static 方法只能被 “覆盖” 为 static 的方法
    而这个操作并不能叫做覆盖 因为原来 A 的 mothodThree() 还是可以被以 static 的方式调用
    所以之称为 hidden
      

  2.   

    查了一下
    The Java™
    Language Specification
    Second Edition
    有这么一段8.4.8.5 Example: Invocation of Hidden Class Methods
    A hidden class (static) method can be invoked by using a reference whose type
    is the class that actually contains the declaration of the method. In this respect,
    hiding of static methods is different from overriding of instance methods. The
    example:class Super {
    static String greeting() { return "Goodnight"; }
    String name() { return "Richard"; }
    }
    class Sub extends Super {
    static String greeting() { return "Hello"; }
    String name() { return "Dick"; }
    }
    class Test {
    public static void main(String[] args) {
    Super s = new Sub();
    System.out.println(s.greeting() + ", " + s.name());
    }
    }produces the output:
    Goodnight, Dickbecause the invocation of greeting uses the type of s, namely Super, to figure
    out, at compile time, which class method to invoke, whereas the invocation of
    name uses the class of s, namely Sub, to figure out, at run time, which instance
    method to invoke.看来要多看
      

  3.   

    上面那段贴错了
    应该是这段 不好意思
    8.4.6.2 Hiding (by Class Methods)
    If a class declares a static method, then the declaration of that method is said to
    hide any and all methods with the same signature in the superclasses and superinterfaces
    of the class that would otherwise be accessible to code in the class. A
    compile-time error occurs if a static method hides an instance method.
    In this respect, hiding of methods differs from hiding of fields (§8.3), for it is
    permissible for a static variable to hide an instance variable. Hiding is also distinct
    from shadowing (§6.3.1) and obscuring (§6.3.2).
    A hidden method can be accessed by using a qualified name or by using a
    method invocation expression (§15.12) that contains the keyword super or a cast
    to a superclass type. In this respect, hiding of methods is similar to hiding of
    fields.
      

  4.   

    telenths(_非法操作_) 已经说的很清楚了,我也不用多说了