oop

5. Method Hiding: Static Methods

Analyze the code, write your predicted output, and then reveal the solution.

Scenario

Can we override a static method? No. Static methods belong to the class, not the instance.

Code Block
class Base { static void display() { System.out.println("Base Static"); } } class Derived extends Base { static void display() { System.out.println("Derived Static"); } } public class Main { public static void main(String[] args) { Base obj = new Derived(); obj.display(); // Warning: Static method should be accessed in a static way } }
Take Your Shot
Predicted Output

Type exactly what you think will be printed in the console.

5. Method Hiding: Static Methods | DevExCode