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 / ramandeep

Yes you can override static methods..
see the following two classes :
public class Super
{
public static void main(String args[])
{

}

public static void m1()
{
System.out.println("superclass");
}
}


public class Sub extends Super
{
public static void main(String args[])
{
Super superWalaObj = new Sub();
superWalaObj.m1();

Sub subWalaObj = new Sub();
subWalaObj.m1();
}

public static void m1()
{
System.out.println("subclass");
}
}

Running this gives the following output :
superclass
subclass

Which explains the behaviour itself.

By overriding the static methods we are forcing them to
behave as non-static methods when used with object.
However, making a call directly to the staticy. method will
call the method belonging to that class only

Is This Answer Correct ?    7 Yes 1 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

How would you reatach detached objects to a session when the same object has already been loaded into the session?

1218


How are the elements of a cardlayout organized?

1085


Explain the advantages and disadvantages of detached objects.

1030


what are getters and setters in Java with examples?

1786


How will you pass parameters in RMI? Why do you serialize?

1246


What are the design considerations while making a choice between using interface and abstract class?

1103


What are the types of scaling?

1092


What are the different algorithms used for clustering?

1074


What are the steps to write p-to-p model application?

2487


how to use debug in my elipse to solve problems that exist in my project

2286


How would you detect a keypress in a jcombobox?

1146


Which class is the immediate superclass of the menucomponent class?

1205


Describe responsibilities of Activator?

2277


Is there a guarantee of uniqueness for entity beans?

1014


What you mean by COM and DCOM?

1065