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

Java · Theory

this Keyword in Java

← All stacks

Theory

32/270

this Keyword in Java

this means this current object. In a constructor, this.name = name; copies the parameter into the field. Without this, name = name; only changes the local parameter — a very common bug.

this.method() calls another method on the same object. this() calls another constructor in the same class and must be the first statement. static methods have no this, because there is no current object.

Show the classic constructor this.name = name; in interviews.

Let's take this on the board with one tiny Main class — no extra files. this Keyword in Java — output: Asha. Without this.name = name, the field would stay null — parameter would hide the field. Start from main, go line by line, and stop at each print. That output is the proof for this Keyword.

Exam tip

Show this.name = name in a constructor.

Example

class Person {
  String name;
  Person(String name) {
    this.name = name; // field = parameter
  }
}

public class Main {
  public static void main(String[] args) {
    Person p = new Person("Asha");
    System.out.println(p.name);
  }
}

this Keyword in Java — output: Asha. Without this.name = name, the field would stay null — parameter would hide the field.

Short notes

  • Defthis = this current object.
  • Rulethis.name = name; sets the field from the parameter.
  • Rememberthis() calls another constructor. Must be first statement.
  • TrapNo this in static methods. name = name; does not set the field.

Questions

1

What does this mean?

2

Why this.name = name?

3

Can you use this in static?

Previous← static keyword in JavaNextInheritance 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.