File tree Expand file tree Collapse file tree 1 file changed +29
-0
lines changed Expand file tree Collapse file tree 1 file changed +29
-0
lines changed Original file line number Diff line number Diff line change @@ -130,3 +130,32 @@ obj.run();
130
130
Output: Bike is running safely
131
131
```
132
132
133
+ 3 . Static method hiding
134
+ ``` java
135
+ class Parent {
136
+ // Static method in the parent class
137
+ static void display () {
138
+ System . out. println(" Static method in Parent class" );
139
+ }
140
+ }
141
+
142
+ class Child extends Parent {
143
+ // Static method in the child class (hiding the parent method)
144
+ static void display () {
145
+ System . out. println(" Static method in Child class" );
146
+ }
147
+ }
148
+
149
+ public class MethodHidingExample {
150
+ public static void main (String [] args ) {
151
+ Parent obj1 = new Parent ();
152
+ Parent obj2 = new Child ();
153
+ Child obj3 = new Child ();
154
+
155
+ obj1. display(); // Calls Parent's display method
156
+ obj2. display(); // Calls Parent's display method (reference type determines the method)
157
+ obj3. display(); // Calls Child's display method
158
+ }
159
+ }
160
+
161
+ ```
You can’t perform that action at this time.
0 commit comments