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

Java · Theory

Methods in Java

← All stacks

Theory

29/270

Methods in Java

A method is a reusable block that does one job. Parts: return type, name, parameters, body. void means do the work and return nothing. int square(int n) returns a value.

Call it on an object: s.study(); or on the class if it is static: Math.max(2, 5). Keep methods small — one clear responsibility. Forgetting return in a non-void method is a compile error.

In an interview, write square(int n) live and explain each word of the signature.

Let's take this on the board with one tiny Main class — no extra files. Methods in Java — output: 25. square(5) is 5*5. Change to square(6) in your head — 36. Start from main, go line by line, and stop at each print. That output is the proof for Methods.

Exam tip

Explain signature: return type + name + params. Write square(int n).

Example

public class Main {
  static int square(int n) {
    return n * n;
  }

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

Methods in Java — output: 25. square(5) is 5*5. Change to square(6) in your head — 36.

Short notes

  • DefA method is a reusable block that does one job.
  • RuleSignature = return type + name + parameters.
  • Remembervoid returns nothing. Non-void must return a value.
  • Useobject.method() or Class.staticMethod().

Questions

1

What is a method?

2

What does void mean?

3

What is a method signature?

Previous← Java Classes and ObjectsNextConstructors 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.