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

Java · Theory

Call by Value and Call by Reference in Java

← All stacks

Theory

64/270

Call by Value and Call by Reference in Java

Java is call by value. For int, the method gets a copy. Changing the copy does not change the caller’s variable.

For objects, the method gets a copy of the reference (the arrow). Both arrows point to the same object, so field changes are visible. If the method does obj = new Thing(), the caller’s arrow does not change.

The trap is saying “Java is call by reference”. It is not. It is call by value — the value of the reference is copied.

Let's take this on the board with one tiny Main class — no extra files. Output: Asha scored 72 then Pass. Real Main. Swap marks/name to show one idea from Call by Value and Call by Reference in Java. Start from main, go line by line, and stop at each print. That output is the proof for Call by Value and Call by Reference.

Exam tip

Say: Java is call by value. For objects the reference is copied, not the object.

Example

// Call
public class Main {
  public static void main(String[] args) {
    int marks = 72;
    String name = "Asha";
    System.out.println(name + " scored " + marks);
    if (marks >= 40) System.out.println("Pass");
  }
}

Output: Asha scored 72 then Pass. Real Main. Swap marks/name to show one idea from Call by Value and Call by Reference in Java.

Short notes

  • DefJava is call by value. Primitives copy the number. Objects copy the reference.
  • RuleField changes are visible. Reassigning the parameter is not.
  • TrapSaying Java is call by reference.
  • RememberSame object, copied arrow.

Questions

1

Is Java call by reference?

2

What is copied for objects?

Previous← Recursion in JavaNextJava Enums →
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.