Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7880001
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T04:02:21+00:00 2026-06-03T04:02:21+00:00

In case of static method overriding ..I have developed this below code class Ab

  • 0

In case of static method overriding ..I have developed this below code

class Ab {  
    static void getF() {
        System.out.println("I am saral");
    }
}

class Ham extends Ab {
    static void getF() {
        System.out.println("I am saral saxena");
    }
    public static void main(String[] args) {
        // Ham h = new Ham();
        // h.getF(); //Ham
        Ab a = new Ham();
        a.getF(); // Ab class
    }
}

Now my query is that in case of static method overriding when i am using polymorphic behavior, Ab a = new Ham(); at this stage I am still getting the method getF(); of class Ab, please advise.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-03T04:02:23+00:00Added an answer on June 3, 2026 at 4:02 am

    You can’t override a static method.

    Static methods belong to classes. You can call Ab.getF() or Ham.getF() – you chose which when you code.

    Naming static methods the same in a class hierarchy has no impact whatsoever (other than possible confusion for programmers). Static methods are floating bits of code that belong to classes, not instances. Only instance methods are sensitive to overriding.

    For this reason, it is poor style to call a static method on an instance (as you have), because it makes the method appear to be an instance method. It’s allowed in the language, but leads to programmer confusion, and therefore bugs, especially if the static method has a name like an instance method – eg discovering that a method named setName(String) was a static method could be grounds for justifiable homicide.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

in this code : public class Main{ private void method() { System.out.println(inside method); }
I have a use case where I need to call a (non-static) method in
I have task to get static method using reflection like this : myType.GetMethod(MyMethod,BindingFlags.Static |
If I have a static method like this private static bool TicArticleExists(string supplierIdent) {
Suppose you have a private static method called Inst() which allows the class to
In Inheritance concept, i have a static method in super class and i am
I have a static method on a public class. Example: public class MyClass {
I have a Junit4 test case which statically imports the org.junit.Assert.assertEquals method(s). import static
I have a static method in a cpp file (not in class) . I
Below is a simplified version of code I've written to override a class method

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.