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 onl

Is This Answer Correct ?    9 Yes 7 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

What is the immediate superclass of the applet class?

1066


Which textcomponent method is used to set a textcomponent to the read-only state?

1115


Which class is the immediate superclass of the menucomponent class?

1189


Why a component architecture for the java platform?

1191


Explain what is orm?

1086


What you mean by COM and DCOM?

1048


What is bean? Where can it be used?

1133


What are the sequence of steps to write pub or sub model kind of application?

2507


What are the different class loaders used by jvm?

1090


What is a class loader?

1852


What is ripple effect?

1058


What are the different methods of identifying an object?

1052


What is a tasks priority and how is it used in scheduling?

1044


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

6514


Is the ternary operator written x : y ? Z or x ? Y : z ?

1091