Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-6249774

hide vs override error message

XMLWordPrintable

    • generic
    • generic

      From: ###@###.###
      Date: Sat, 02 Apr 2005 19:53:14 -0800

         If I try to compile this bogus program:

      class Base {
          public static String getName() { return "Base"; }
      }

      class Derived extends Base {
          private static String getName() { return "Derived"; }
      }

      public class PrivateMatter {
          public static void main(String[] args) {
              System.out.println(new Derived().getName());
          }
      }

      The compiler saith:

      PrivateMatter.java:6: getName() in Derived cannot override getName()
      in Base; attempting to assign weaker access privileges; was public
          private static String getName() { return "Derived"; }
                                ^
      1 error

      Of course the word "override" in the diagnostic should be replaced by
      the word "hide," as these are static methods and only instance methods
      can be overridden.

      ###@###.### 2005-04-03 04:48:40 GMT

            Unassigned Unassigned
            ahe Peter Ahe
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Imported:
              Indexed: