PGoCareerGoCareer prep tools
Home
LoginSign up
  • Java
  • Python
  • AI
  • React
  • Angular
  • PHP
  • Node.js
  • SQL
  • DSA
  • HTML
  • CSS
  • JS
  • Spring
  • ML
  • MongoDB

Java · Theory

static keyword in Java

← All stacks

Theory

31/270

static keyword in Java

static means it belongs to the class, not to each object. A static field is one shared copy — like a common counter. A static method can be called without new: Math.max, main.

main is static so the JVM can start it without making your class object first. static methods cannot use this or instance fields directly. You need an object for those.

Use static for shared utilities. Making everything static is usually poor design. Accessing instance variables from static without an object is a compile error.

Let's take this on the board with one tiny Main class — no extra files. static keyword in Java — output: 1. count belongs to the class, not to an object. main can use it without new Main(). Start from main, go line by line, and stop at each print. That output is the proof for static keyword.

Exam tip

Explain why main must be static.

Example

public class Main {
  static int count = 0;

  public static void main(String[] args) {
    count++;
    System.out.println(count);
  }
}

static keyword in Java — output: 1. count belongs to the class, not to an object. main can use it without new Main().

Short notes

  • Defstatic belongs to the class, not to each object.
  • Rulestatic field = one shared copy. static method = call without new.
  • Remembermain is static so JVM can start the program.
  • Trapstatic methods cannot use this or instance fields directly.

Questions

1

What does static mean?

2

Why is main static?

3

Can a static method use this?

Previous← Constructors in JavaNextthis Keyword in Java →
P

GoCareerGo

Utilities · Preparation Hub · Resume · CV · Tools — one workspace.

Workspace

DashboardProfilePreparation HubResume builderCV builderCareer planning

PDF Tools

Merge PDFSplit PDFCompress PDFImage to PDFAll toolsJobs

Image & QR

Compress ImageResize ImageQR ScannerQR GeneratorBlogIT interview prep

Company

FAQFeedbackContactPrivacyTermsSitemap

© 2026 GoCareerGo. Keep moving forward.