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 8831327
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T08:17:06+00:00 2026-06-14T08:17:06+00:00

If static methods are resolved at compile time how is an object instance able

  • 0

If static methods are resolved at compile time how is an object instance able to call a static method?

class StaticCall
{
    public static void main(String[] args)
    {
        String arr[]={"Class StaticCall","calls static method of class MyMainClass"};

        MyMainClass h=new MyMainClass();
        h.main(arr);         //How is an instance able to call a static method?
        System.out.println("this is StaticCall main");  
    }   

}


class MyMainClass 
{
    public static void main(String[] args){
        System.out.println(args[0]+" "+ args[1]);
    }
}

After running the StaticCall class the output is

Class StaticCall calls static method of class MyMainClass

this is StaticCall main

As static fields and methods belong to the Class object how is an instance able to call a static method?
Also when is the Class object created,Is it on first access to any of it’s fields or methods?

  • 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-14T08:17:07+00:00Added an answer on June 14, 2026 at 8:17 am

    How is an instance able to call a static method?

    It doesn’t. Try this instead

    MyMainClass h = null;
    h.main(arr);   
    

    and you will see that the instance is ignored as this is exactly the same as

    MyMainClass.main(arr);   
    

    To extend your example … if you have

    class AnotherMainClass extends MyMainClass 
    {
    }
    

    then all the following call the same method.

    AnotherMainClass amc = null;
    amc.main(args);
    
    ((AnotherMainClass) null).main(args);
    
    AnotherMainClass.main(args);
    
    MyMainClass mmc = null;
    mmc.main(args);
    
    ((MyMainClass) null).main(args);
    
    MyMainClass.main(args);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

The following code doesn't compile. package varargspkg; public class Main { public static void
The method is defined as below: public static void checkNotNull<T extends Throwable>(Object value, String
Is using an instance of a class to access static methods considered bad practice?
I know this represents the object invoking the method and static methods are not
I have an extension method here like this: public static class Extensions { public
I have a static methods class, Utils, that is basically for utility methods, its
I heard that static methods should use only static variables in java. But, main
I've been reading that the static methods of the File Class are better used
A college at work created a class with only static methods. Because he wants
I understand at a low level what static (compile time) and dynamic (runtime) bindings

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.