Article Categories
- All Categories
-
Data Structure
-
Networking
-
RDBMS
-
Operating System
-
Java
-
MS Excel
-
iOS
-
HTML
-
CSS
-
Android
-
Python
-
C Programming
-
C++
-
C#
-
MongoDB
-
MySQL
-
Javascript
-
PHP
Selected Reading
What is method hiding in Java and how to use it?
When super class and sub class contains same method including parameters and if they are static.
The method in the super class will be hidden by the one that is in the sub class. This mechanism is known as method hiding.
Example
class Demo{
public static void demoMethod() {
System.out.println("method of super class");
}
}
public class Sample extends Demo {
public static void demoMethod() {
System.out.println("method of sub class");
}
public static void main(String args[] ) {
Sample.demoMethod();
}
}
Output
method of sub class
Advertisements
