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,607
    My Mood
    Hungover
    Thanks
    145
    Thanked 658 Times in 563 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
    6,307
    My Mood
    Mellow
    Thanks
    252
    Thanked 779 Times in 764 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
    80
    Thanks
    0
    Thanked 8 Times in 8 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 10: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
    6,307
    My Mood
    Mellow
    Thanks
    252
    Thanked 779 Times in 764 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, 04: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, 05:13 AM
  3. Replies: 6
    Last Post: May 3rd, 2013, 05:25 PM
  4. Replies: 1
    Last Post: April 3rd, 2012, 07:32 AM
  5. Replies: 10
    Last Post: September 6th, 2010, 05:48 PM