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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T02:16:49+00:00 2026-06-12T02:16:49+00:00

Can someone please explain the difference between the following cases and where would we

  • 0

Can someone please explain the difference between the following cases and where would we use each one?
Thanks all

class A{
  static public void methodA()
}

static class B{
  static public void methodB()
}

static class C{
  public void methodC()
}

Edit:
Hello all thank for the answers. I maybe I was not clear enough. I am aware that classes B and C can not be declared static unless they are inner classes. I so in your answers please assume that they are inner classes. I want to know when would I declare them static and even when to declare their methods static. I know that a static method in a non static class means that you can call it from anywhere and it is generally to perform general operations that are not specific to an object. But why would you declare static class?
I will check your answers again after you reread my edit and accept the most explanatory answer

  • 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-12T02:16:50+00:00Added an answer on June 12, 2026 at 2:16 am

    The static modifier is used to declare static fields or class variables.

    They are associated with the class, rather than with any object. Every
    instance of the class shares a class variable, which is in one fixed
    location in memory. Any object can change the value of a class
    variable, but class variables can also be manipulated without creating
    an instance of the class.

    Source: “Understanding Instance and Class Members”

    Also note that Java supports both static variables and methods. So going by this, your first class would compile correctly, while the other two would fail.

    Just to give an example:

    class A{
        public static int STATIC_VALUE = 1; // is a valid static variable
    
        public static void method1(){ 
            //is a valid static method
        }
    
        /**
        * Is a valid static inner class
        */
        static class innerClassB{
    
        }
    }
    

    But why would you declare static class?

    There’re some reasons as to why one might want to do that. For example, from this Java Tutorial:

    A static nested class interacts with the instance members of its outer
    class (and other classes) just like any other top-level class. In
    effect, a static nested class is behaviorally a top-level class that
    has been nested in another top-level class for packaging convenience.

    A good example of this is the static class Entry<K,V> implements Map.Entry<K,V> used in places like the HashMap class.

    The existence of the Entry class is closely related to the functioning of how HashMap stores/retrieves key/value pair stored as its content. As you can see the Entry class provides functionality only to the HashMap implementation, even though its behaviorally equivalent to a top-level class. So it does make sense to package it as part of the HashMap definition itself.

    You can find similar usage with private static class Entry<E> in the LinkedList implementation.

    Another reason that I can think of is a way for white-box testing. Since an inner static class has access to the private and protected static variables/methods of the outer class, you can very well use this to test the internal states of the outer class. Some might consider this dirty but then it can sometimes be useful

    In my opinion, Static inner classes are mostly for convenience, and are generally based on your design principles.

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

Sidebar

Related Questions

Can someone please explain the difference between the following methods to me? it should
Can someone please explain the difference between the following queries. The joins in the
Can someone please explain the difference between the following two options of Tortoise SVN
Can someone please explain to me difference between extends and super in java generics
Can someone please explain to me the difference between the AppSettings and ApplicationSettings sections
Can someone please explain with example that I can understand about the difference between
Can someone please explain the difference between ViewState and Session? More specifically, I'd like
Can someone please explain the difference between IE8 browser mode and document mode in
Can someone please explain what is the main difference between SQL Server Compact Edition
can someone please explain the difference between these 2 pieces of code: var temp

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.