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

Is a class a subclass of itself?

1150


what are memory considerations of jsp compares to other web components?

6478


How are commas used in the intialization and iteration parts of a for statement?

1061


For which statements does it make sense to use a label?

1036


What are the types of scaling?

1055


What is the difference between java class and bean?

1039


What is difference between object state and behavior?

1060


What is the map interface?

1095


Why are component architectures useful?

1021


When is the best time to validate input?

1071


How are the elements of a borderlayout organized?

1064


Will the general public have access to the infobus apis?

1012


Which javutil classes and interfaces support event handling?

1007


Why a component architecture for the java platform?

1143


What is a session? Can you share a session object between different theads?

947