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 / konthoujam dhanabir singh

static method cannot be overriden to non-static.so static
method can be overriden to static.
the above example is true in static way
e.g.

class Animal {
static void doStuff() {
System.out.print("a ");
}
}

class Dog extends Animal {
static void dostuff() { // it's a redefinition,
// not an override
System.out.print("d ");
}

public static void main(String [] args) {
Animal [] a = {new Animal(), new Dog(), new Animal()};
for(int x = 0; x < a.length; x++)
a[x].doStuff(); // invoke the static method
}
}

Running this code produces the output:
a a a
Some case:
in the subclass Dog, if the method dostuff() is not
static,it will be compile time error in the above code
block .
So a static method cannot be overriden

Is This Answer Correct ?    2 Yes 0 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

Explain RMI Architecture?

1099


What is the argument type of a programs main() method?

1120


Is it possible to stop the execution of a method before completion in a sessionbean?

1093


How is a java object message delivered to a non-java client?

1054


What are the services in RMI ?

2385


What value does read() return when it has reached the end of a file?

1035


what is an isolation level?

2762


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

1039


Explain about local interfaces.

1066


What method is invoked to cause an object to begin executing as a separate thread?

1041


what is meant by JRMP?

2358


What is permgen or permanent generation?

1028


What is the purpose of the wait() method?

1206


Why does the option tag render selected=selected instead of just selected?

1180


To what value is a variable of the string type automatically initialized?

1138