Can we override static method in Java?

By | August 9, 2019

In this post we will discuss about one of very tricky core java interview question and question is that Can we override static method in Java?

This is the trickiest Java interview question.

Static methods cannot be overridden in the exact sense of the word, but they can hide parent static methods.

Parent class static methods are not part of a child class (although they are accessible), so there is no question of overriding it. Even if you add another static method in a subclass, identical or with same method signature to the one in its parent class, this subclass static method is unique and different from the static method in its parent class.

This Java Program will show that, we can not override static method in Java. If you declare same method in subclass then It is known as method hiding.

 Output of above program:

That’s all about  Can we override the static method in Java?

You May Also Like:

Can we call static method with null object?
Why should I choose Java for Software Development? What are Pros and Cons of Java?
Can we cast an int value into byte type variable? what if the value of int is larger than byte?
Can We store a double value in a long type variable without casting?
How many ways we can create an object in Java?
Why Java is not 100% Object-oriented language?
What are the differences between 32-bit and 64-bit versions of Java?
What will be the output of following java program?
What is the difference Between java.util.Date and java.sql.Date in Java ?
What is difference between using Serializable & Externalizable Interfaces in Java?
Which Java data type would you choose for storing sensitive information, like passwords, and Why?
What is left shift << and Unsigned right shift >>> operator in Java? How are these useful?

If you have any feedback or suggestion please feel free to drop in below comment box.

Leave a Reply

Your email address will not be published. Required fields are marked *