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 / konthoujan 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 .

Is This Answer Correct ?    5 Yes 5 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

Can constructors be synchronized in java?

1176


What is scalable, portability in the view of J2EE?

2579


Explain the steps in details to load the server object dynamically?

5146


What is the difference between ear, jar and war file?

1191


When a thread blocks on i/o, what state does it enter?

1159


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

1106


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

2559


What are local interfaces? Describe.

1307


What is ripple effect?

1131


Explain how will the struts know which action class to call when you submit a form?

1015


What is a policy?

2352


Why are some of the class and element names counter-intuitive?

1219


What is message driven beam?

1123


Write a singleton program?

1110


Do I have to use jsps with my application?

1072