The blog of Jafar Aliyev

Archive

Creation date:

Static methods can not be overriden

 class A {
   static void test(double d){
     System.out.println("method of A");
   }
 }

 public class B extends A{
   static void test(double d){
     System.out.println("method of B");
 }

   public static void main(String... args) {
      A b = new B();
      b.test(3.8);
    }
 }

The result will be

method of Aa

because static methods can't be overriden polymorphism will not take place.

Author: Jafar N.Aliyev (Jsoft)

Read also

Use instanceof carefully
Usage of 'instanceof' method in some situations will give you a compilation error

Java access and nonaccess modifiers
Look at this cheat sheet for Java access and nonaccess modifiers

© Copyright

All articles in this site are written by Jafar N.Aliyev. Reproducing of any article must be followed by the author name and link to the site of origin(this site). This site also keeps the same rules relative to the articles of other authors.