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 task's priority is used in scheduling?

2342


Which are the different segments of memory?

1148


What is the difference between session and entity beans?

1175


What are the difference between RMI and CORBA?

1171


What is chat area? Explain.

1069


What do you need to set-up a cluster with jboss?

1125


Which characters may be used as the second character of an identifier, but not as the first character of an identifier?

1104


What if the static modifier is removed from the signature of the main method?

1305


What is the difference between a static and a non-static inner class?

1212


What are the services in RMI ?

2447


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

1263


Describe, in general, how java's garbage collector works?

1082


What are JTA/JTS and how they used by client?

2266


How would you create a button with rounded edges?

1244


What is the relationship between an event-listener interface and an event-adapter class?

1183