
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Are Static Methods Inherited in Java?
The static keyword is used to create methods that will exist independently of any instances created for the class.
Static methods do not use any instance variables of any object of the class they are defined in. Static methods take all the data from parameters and compute something from those parameters, with no reference to variables.
We can inherit static methods in Java.
Example
In the example we are creating a class named Demo and, declared a static method named display().
We created another class Sample, extended the Demo class and tried to access the display() method using the sub class object.
Example
class Dem{ public static void display(){} } public class Sample extends Dem { public static void display(){ System.out.println("Hello this is a static method"); } public static void main(String args[]) throws Exception{ new Sample().display(); } }
Output
Hello this is a static method
Advertisements