Back
You can prefer the below code which will help you understand the concept of method hiding:
public class Animal { public static void foo() { System.out.println("Animal"); }}public class Cat extends Animal { public static void foo() { // hides Animal.foo() System.out.println("Cat"); }}
public class Animal {
public static void foo() {
System.out.println("Animal");
}
public class Cat extends Animal {
public static void foo() { // hides Animal.foo()
System.out.println("Cat");
I hope this will help.
Want to know more about Java? Prefer this tutorial on Java Tutorial.
Want to become a Java Expert? Join Java Certification now!!
31k questions
32.8k answers
501 comments
693 users