Search...
FAQs
Subscribe
Pie
FAQs
Recent topics
Flagged topics
Hot topics
Best topics
Search...
Search within Beginning Java
Search Coderanch
Advance search
Google search
Register / Login
Post Reply
Bookmark Topic
Watch Topic
New Topic
programming forums
Java
Mobile
Certification
Databases
Caching
Books
Engineering
Micro Controllers
OS
Languages
Paradigms
IDEs
Build Tools
Frameworks
Application Servers
Open Source
This Site
Careers
Other
Pie Elite
all forums
this forum made possible by our volunteer staff, including ...
Marshals:
Campbell Ritchie
Ron McLeod
Tim Cooke
Liutauras Vilda
Jeanne Boyarsky
Sheriffs:
Paul Clapham
Rob Spoor
Junilu Lacar
Saloon Keepers:
Stephan van Hulst
Tim Holloway
Piet Souris
Carey Brown
Bartenders:
Forum:
Beginning Java
Query in the topic static
shalini saranya
Greenhorn
Posts: 6
posted 11 years ago
Number of slices to send:
Optional 'thank-you' note:
Send
Hi all
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 } }
what is the output of above code?
Is it a a a or a d a?
Matthew Brown
Bartender
Posts: 4568
9
posted 11 years ago
Number of slices to send:
Optional 'thank-you' note:
Send
The best thing to do is actually try it yourself - compile the code and run it. Then try and work out
why
that's the output, and if you don't understand come back to us, and we can try and explain it.
Campbell Ritchie
Marshal
Posts: 77157
370
posted 11 years ago
Number of slices to send:
Optional 'thank-you' note:
Send
And also always tell us where you
found such examples
.
shalini saranya
Greenhorn
Posts: 6
posted 11 years ago
Number of slices to send:
Optional 'thank-you' note:
Send
I got the question from the book
SCJP
6 by kathy sierra
Campbell Ritchie
Marshal
Posts: 77157
370
posted 11 years ago
Number of slices to send:
Optional 'thank-you' note:
Send
Thank you.
Anshul K Jain
Greenhorn
Posts: 20
I like...
posted 11 years ago
Number of slices to send:
Optional 'thank-you' note:
Send
Good question for getting the idea of the static method.
reply
reply
Bookmark Topic
Watch Topic
New Topic
Boost this thread!
Similar Threads
confuse for static method
Why did I get this Outout?!
static method can't be overridden but this code is not?
Static method : Redefinition or an override ?
for static
More...