Golgappa.net | Golgappa.org | BagIndia.net | BodyIndia.Com | CabIndia.net | CarsBikes.net | CarsBikes.org | CashIndia.net | ConsumerIndia.net | CookingIndia.net | DataIndia.net | DealIndia.net | EmailIndia.net | FirstTablet.com | FirstTourist.com | ForsaleIndia.net | IndiaBody.Com | IndiaCab.net | IndiaCash.net | IndiaModel.net | KidForum.net | OfficeIndia.net | PaysIndia.com | RestaurantIndia.net | RestaurantsIndia.net | SaleForum.net | SellForum.net | SoldIndia.com | StarIndia.net | TomatoCab.com | TomatoCabs.com | TownIndia.com
Interested to Buy Any Domain ? << Click Here >> for more details...

can a static method be overridden

Answer Posted / ashish

Hi All,

static method can never be overridden, to clear your doubt
I have written the following two java files

Base.java -->
public class Base {
public static void method(){
System.out.println("base");
}
}

Child.java -->
public class Child extends Base {
public static void method(){
System.out.println("Child");
}
public static void main(String[] args) {
Base baseObj = new Child();
baseObj.method();
baseObj = new Base();
baseObj.method();
}
}

The class file for Child.java is:
public class Child extends Base
{

public Child()
{
}

public static void method()
{
System.out.println("Child");
}

public static void main(String args[])
{
Base baseObj = new Child();
Base.method();
baseObj = new Base();
Base.method();
}
}

As you can see in case of static method object got replaced
by Class Name(here Base).
And i believe you all are aware of fact that overridden is
the case when resolution is done at Runtime.

But since in our case calling is decided at compile time,
so there is no case of overridden.

Do let me know, if you have further query

Is This Answer Correct ?    0 Yes 1 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

Can I run seam outside of jboss as?

1079


What restrictions are placed on the values of each case of a switch statement?

1024


Which javutil classes and interfaces support event handling?

1046


What must a class do to implement an interface?

1201


What is a sessionfactory? Is it a thread-safe object?

1220


How are the elements of a borderlayout organized?

1118


What is a modular application? What does module-relative mean?

1063


Are there books about seam?

1111


Is it possible to stop the execution of a method before completion in a sessionbean?

1092


Define aop(assepct oriented programing)?

1182


What do you mean by Socket Programming?

1090


What is the diffrence between a local-tx-datasource and a xa-datasource?

1057


What is prototype?

1169


Can you control when passivation occurs?

1068


What is the difference between a menuitem and a checkboxmenuitem?

1119