SE450: Java: Hiding [7/41] Previous pageContentsNext page

Hiding refers to the introduction of a field (instance or class) or a class method in a subclass that has the same name as a field or a class method in the superclass.

        public class A {
            int x;
            void y() { ... }
            static void z() { ... }
        }
        public class B extends A {
            float x;                // hiding
            void y() { ... }        // overriding
            static int z() { ... }  // hiding
        }
        

You should avoid hiding

Previous pageContentsNext page