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 we override static methods?

Answer Posted / madan mohanp

we cannot override a static method but we can overload a
static method.
Ex: override is not possible
class Foo {
public static void classMethod() {
System.out.println("classMethod() in Foo");

}

public void instanceMethod() {
System.out.println("instanceMethod() in Foo");
}
}

class Bar extends Foo {
public static void classMethod() {
System.out.println("classMethod() in Bar");

}

public void instanceMethod() {
System.out.println("instanceMethod() in Bar");
}
}

class StaticHiding {
public static void main(String[] args) {
Foo f = new Bar();

f.instanceMethod();
f.classMethod();


when u run this program output will be:
instanceMethod() in Bar
classMethod() in Foo.

Ex: overload is possible
public class abc
{
public static void main(String args[])
{

}
public static void trss()
{

}
public static void trss(int i)
{
}

}

Is This Answer Correct ?    15 Yes 4 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

What is data type modifier?

880


What is args length in java?

1117


what invokes a threads run() method? : Java thread

960


Why is singleton instance static?

941


When parseint method can be used?

890


Can a singleton class be inherited?

906


Why is an interface be able to extend more than one interface but a class can’t extend more than one class?

1109


Which is faster call by value or call by reference?

864


Say any two properties in beans?

1017


What is the base class of all exception classes in java?

998


explain copyonwritearraylist and when do we use copyonwritearraylist?

896


What is a numeric format?

1001


What is the purpose of the finally clause of a try-catch-finally statement in java programming?

888


can java object be locked down for exclusive use by a given thread? : Java thread

1018


What is parameter example?

958