Why static methods cant be overridden in java?

Discussion in 'Object Oriented Concepts' started by geetanjali67, May 20, 2010.

  1. geetanjali67

    geetanjali67 New Member

    Why static methods can not be overridden in java?
     
  2. mmk

    mmk New Member

    Re: overriding in static

    Well,

    Overriding will come to the picture with the objects i mean runtime. Static talks about the class and it is related to the class methods i mean static methods. Even if try to override the static method, the compiler didn't look the static method because it has been hidden and the result you won't get any compile time error and we will assume it has overrided but the bottom line is the static method has been hidden.
     
  3. parulmahajan

    parulmahajan New Member

    Re: overriding in static

    Static method are one time method. they get loaded when class is loaded and we cant override them
     
  4. tumma_suryaprakash

    tumma_suryaprakash New Member

    The primary memory which is divided in to three types they are heap area,method area,stack area. The objects of java resides in heap area obuviously instance methods store in heap area. All static methods jvm will stores in th method area. when ever the class is loaded all the static methods are stored in the method area. In method area the jvm doesn,t allows the same type to store again.
    Note : when ever the class is loaded first all the static variables and static blocks last static methods are stored in the jvm.And the important point to remember is static methods should be called with respect to class name.
     
  5. bhabani.pattanayak

    bhabani.pattanayak New Member

    static methods can not be overridden
    this is because method overridding occears in run time when objects are created.
    but the static methods are loaded when first class is loaded, till that time there are no objects in memory,
     
    Last edited: Jul 23, 2010
  6. Anwarraja

    Anwarraja New Member

    But it's possible :confused:

    Consider below:

    class MySuper
    {
    static void sd()
    {
    System.out.println("I ammmmm MySuper");
    }
    }
    public class MySub extends MySuper

    {
    static void sd()
    {
    System.out.println(" I am MySub");
    }


    public static void main(String ...a)
    {
    MySub my=new MySub();
    my.sd();

    }
    }
     
  7. sumitthakur

    sumitthakur New Member

    class MySuper
    {
    static void sd()
    {
    System.out.println("I ammmmm MySuper");
    }
    }
    public class MySub extends MySuper

    {
    static void sd()
    {
    System.out.println(" I am MySub");
    }


    public static void main(String ...a)
    {
    MySub my=new MySub();
    my.sd();

    }
    }


    / it is call redefine /
     
  8. anneroberts

    anneroberts Member

    A example system can't override An static method, and a static technique can't hiddenite an occurrence strategy. To example, those Emulating project need two compiler errors. In An subclass (or inferred Class), we camwood over-burden the routines inherited starting with those superclass.
     

Share This Page