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

Java · Theory

Difference between final, finally and finalize in Java

← All stacks

Theory

98/270

Difference between final, finally and finalize in Java

final locks: variable cannot reassign, method cannot override, class cannot extend. finally is the try cleanup block. finalize is an old GC callback — do not use it in new code.

Viva loves mixing these three. Answer in three short lines. Don’t write one mixed paragraph.

finally is for close(). final is for MAX = 100 or a locked design. finalize is history.

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 Difference between final, finally and finalize in Java. Start from main, go line by line, and stop at each print. That output is the proof for Difference between final, finally and finalize.

Exam tip

Three lines: final locks, finally cleans up after try, finalize is old GC — don’t use it.

Example

// Difference
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 Difference between final, finally and finalize in Java.

Short notes

  • Deffinal = lock. finally = try cleanup. finalize = old GC hook.
  • RuleAnswer in three separate lines.
  • Usefinally close file. final for constants.
  • TrapUsing finalize. Mixing all three words.

Questions

1

What is final?

2

What is finally?

3

Should you use finalize?

Previous← Difference Between throw and throws in JavaNextException Handling with Method Overriding →
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.