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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T01:11:41+00:00 2026-05-11T01:11:41+00:00

To be specific, I was trying this code: package hello; public class Hello {

  • 0

To be specific, I was trying this code:

package hello;  public class Hello {      Clock clock = new Clock();      public static void main(String args[]) {         clock.sayTime();     } } 

But it gave the error

Cannot access non-static field in static method main

So I changed the declaration of clock to this:

static Clock clock = new Clock(); 

And it worked. What does it mean to put that keyword before the declaration? What exactly will it do and/or restrict in terms of what can be done to that object?

  • 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. 2026-05-11T01:11:42+00:00Added an answer on May 11, 2026 at 1:11 am

    static members belong to the class instead of a specific instance.

    It means that only one instance of a static field exists[1] even if you create a million instances of the class or you don’t create any. It will be shared by all instances.

    Since static methods also do not belong to a specific instance, they can’t refer to instance members. In the example given, main does not know which instance of the Hello class (and therefore which instance of the Clock class) it should refer to. static members can only refer to static members. Instance members can, of course access static members.

    Side note: Of course, static members can access instance members through an object reference.

    Example:

    public class Example {     private static boolean staticField;     private boolean instanceField;     public static void main(String[] args) {         // a static method can access static fields         staticField = true;          // a static method can access instance fields through an object reference         Example instance = new Example();         instance.instanceField = true;     } 

    [1]: Depending on the runtime characteristics, it can be one per ClassLoader or AppDomain or thread, but that is beside the point.

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

Sidebar

Ask A Question

Stats

  • Questions 175k
  • Answers 175k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer istringstream a("asd"); istringstream b(a.str()); Edit: Based on your comment to… May 12, 2026 at 3:01 pm
  • Editorial Team
    Editorial Team added an answer Sorry for not giving any references to specs, I'm only… May 12, 2026 at 3:01 pm
  • Editorial Team
    Editorial Team added an answer static IEnumerable<string> Split(string str, int chunkSize) { return Enumerable.Range(0, str.Length… May 12, 2026 at 3:01 pm

Related Questions

Hey all, I want to change a value in a table (in a mysql
I'm trying to parse CSS, or at least the basics, using ANTLR. I'm running
I have a ASP.NET MVC page of Events of a specific day. I'm also
I have a method that takes a System.Web.UI.Page as an input and returns some

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.