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.

Results 1 to 7 of 7

Thread: static method

  1. #1
    Junior Member
    Join Date
    Aug 2014
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default static method

    can a static method be overridden?


  2. #2
    Crazy Cat Lady KevinWorkman's Avatar
    Join Date
    Oct 2010
    Location
    Washington, DC
    Posts
    5,424
    My Mood
    Hungover
    Thanks
    144
    Thanked 636 Times in 540 Posts

    Default Re: static method

    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!

  3. #3
    Junior Member
    Join Date
    Aug 2014
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default static method

    why static method cannot be overridden?

  4. #4
    Super Moderator
    Join Date
    Jun 2013
    Location
    So. Maryland, USA
    Posts
    5,520
    My Mood
    Mellow
    Thanks
    215
    Thanked 698 Times in 680 Posts

    Default Re: static method

    What would it be overridden by?

  5. #5
    Member jdv's Avatar
    Join Date
    Jul 2014
    Location
    This Land
    Posts
    73
    Thanks
    0
    Thanked 5 Times in 5 Posts

    Default Re: static method

    Quote Originally Posted by manali View Post
    why static method cannot be overridden?
    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

  6. #6
    Junior Member
    Join Date
    Jul 2009
    Posts
    5
    Thanks
    0
    Thanked 1 Time in 1 Post

    Default Re: static method

    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.

  7. #7
    Super Moderator
    Join Date
    Jun 2013
    Location
    So. Maryland, USA
    Posts
    5,520
    My Mood
    Mellow
    Thanks
    215
    Thanked 698 Times in 680 Posts

    Default Re: static method

    Threads merged. Please do not post multiple threads on the same topic.

Similar Threads

  1. What are the rules in using Static Method and Static Variable? HELP!
    By BALLISLIFE in forum Object Oriented Programming
    Replies: 3
    Last Post: August 7th, 2013, 03:52 AM
  2. How to call a static method within a static method in the same class?
    By EDale in forum What's Wrong With My Code?
    Replies: 4
    Last Post: May 10th, 2013, 04:13 AM
  3. Replies: 6
    Last Post: May 3rd, 2013, 04:25 PM
  4. Replies: 1
    Last Post: April 3rd, 2012, 06:32 AM
  5. Replies: 10
    Last Post: September 6th, 2010, 04:48 PM