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

Which are the different segments of memory?

1028


What is meant by method chaining?

1095


Describe activation process?

2603


What is the diffrence between a local-tx-datasource and a xa-datasource? Can you use transactions in both?

986


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

986


What is local interface. How values will be passed?

985


What is colon_pkg_prefixes and what is its use?

2464


what are the advantages of JTA over JTS?

2150


What is the difference between a static and a non-static inner class?

1094


What is the difference between session and entity beans?

1053


Explain about local interfaces.

1010


Where can I ask questions and make suggestions about seam?

1016


What is permgen or permanent generation?

968


Java is fully object oriented languages or not?

947


int x=5,i=1,y=0; while(i<=5) { y=x++ + ++x; i=i+2; } System.out.println(x); System.out.println(y); System.out.println(i); How to solve this? Please explain!

1781