can a static method be overridden?
Welcome to the Java Programming Forums
The professional, friendly Java community. 21,500 members and growing!
The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.
>> REGISTER NOW TO START POSTING
Members have full access to the forums. Advertisements are removed for registered users.
can a static method be overridden?
What do you think the answer is? What happened when you wrote a little example program to test your answer?
We aren't going to do your homework for you.
Useful links: How to Ask Questions the Smart Way | Use Code Tags | Java Tutorials
Static Void Games - Play indie games, learn from game tutorials and source code, upload your own games!
why static method cannot be overridden?
What would it be overridden by?
You can't override static methods, but you can hide them: Overriding and Hiding Methods (The Java™ Tutorials > Learning the Java Language > Interfaces and Inheritance)
Overriding decides what to run based on the runtime information. Hiding is a compile time operation based on the type at compilation. Class method invocations are always resolved at compile time, and never at runtime.
This is why good IDEs will warn you if you invoke a static method through an object, even though Java lets you do this as a convenience. It just uses the class of that object resolved at compile time.
Last edited by jdv; August 29th, 2014 at 09:14 AM. Reason: GRAMMAR
overriding happens in runtime, overloading happens in compile-time.Static methods are class properties and they are handled in compile-time.So, static methods cannot be overridden.Try writing some code in your IDE, before you ask.The error that you get will explain a lot.
Threads merged. Please do not post multiple threads on the same topic.