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

  • Home
  • SEARCH
  • 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 8434255
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T06:36:26+00:00 2026-06-10T06:36:26+00:00

Why It calls base class method when we declare method as static in base

  • 0

Why It calls base class method when we declare method as static in base as well as in derive class and do upcasting.

class Base
{
    static void show(){
        System.out.println("Base class....");
    }
}
class Derive extends Base
{
    static void show(){
        System.out.println("Drive class....");
    }//method hidding.....

    public static void main(String[] args) 
    {
        Base b= new Derive();
            b.show();           
    }
}
  • 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-10T06:36:27+00:00Added an answer on June 10, 2026 at 6:36 am

    You’re calling Base.show, not Derive.show. Method hiding is not overriding.

    §8.4.8.2. of the Java Language Specification gives an example that demonstrates exactly what happens here:

    A class (static) method that is hidden can be invoked by using a reference whose type is the class that actually contains the declaration of the method. In this respect, hiding of static methods is different from overriding of instance methods. The example:

    class Super {
        static String greeting() { return "Goodnight"; }
        String name() { return "Richard"; }
    }
    class Sub extends Super {
        static String greeting() { return "Hello"; }
        String name() { return "Dick"; }
    }
    class Test {
        public static void main(String[] args) {
            Super s = new Sub();
            System.out.println(s.greeting() + ", " + s.name());
        }
    }
    

    produces the output:

    Goodnight, Dick

    because the invocation of greeting uses the type of s, namely Super, to figure out, at compile time, which class method to invoke, whereas the invocation of name uses the class of s, namely Sub, to figure out, at run-time, which instance method to invoke.

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

Sidebar

Related Questions

I can't figure out how to call a base class method from a derived
I need to declare finalizing method finalize() for all descendants of the base class
How do we call a virtual method from another method in the base class
Given the following: class BC { public void Display() { System.Console.WriteLine(BC::Display); } } class
Suppose I have this class hierarchy: class A { public: virtual void foo(Base *b)
okay, i'm curious why gcc calls this an ambiguity. check this: class base_stream {
Do system calls execute in the context of a software interrupt handler in entirety?
In C++, you can do the following: class base_class { public: virtual void do_something()
Basically, I have a pure virtual class Base, and a concrete class Derived which
Let say we have a base class and its two derived classes; The base

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.