Start free
OOPs HandbookEquality in OOP (== vs .equals), Method Hiding & String Immutability
ArchitectureIntermediate
8 min read

Equality in OOP (== vs .equals), Method Hiding & String Immutability

Reference equality vs content equality, static method hiding, and String vs StringBuilder vs StringBuffer.

TM
TestMeMan SDE Curriculum
Updated Sept 2026
Verified for FAANG Interviews
FROM TESTMEMAN•TestMeMan Campus

Coding problems with instant test-case feedback

Write Python, C++, C or JavaScript in your browser and see which hidden tests pass.

Sponsored Publisher Placement•
ID: ad-top-leaderboard
Executive Summary

Equality testing and String manipulation are among the most frequently tested interview topics.

1. The Difference Between == and .equals() in Java#

Tricky Question 5: "What is the difference between == and .equals() in Java?"

• == checks for reference equality (whether two object pointers refer to the exact same physical memory address in the heap).

• .equals() checks for content/value equality (whether two distinct objects have the same internal field values).

2. What is Method Hiding?#

Tricky Question 19: "What is method hiding?"

Method hiding occurs when a subclass defines a static method with the exact same signature as a static method in the superclass. Because static methods are resolved at compile-time (early binding), the subclass method simply hides the superclass method, rather than overriding it.

Sponsored ContentTestMeMan Campus

Practise placement aptitude on the real test pattern

TCS NQT, Infosys, Wipro, Accenture and Cognizant style mocks with section-wise analysis.

3. String vs StringBuilder vs StringBuffer#

Tricky Question 26: Comparing the 3 text handling classes:

ClassMutabilityThread SafetyPerformance
StringImmutable (constant once created)Thread-Safe by default (read-only)Slow for heavy concatenations (creates new objects)
StringBuilderMutable (modifies internal buffer)Not Thread-SafeFastest performance for single-threaded string construction
StringBufferMutable (modifies internal buffer)Thread-Safe (synchronized methods)Slightly slower due to thread locking synchronization

4. instanceof vs getClass()#

Tricky Question 22: "What is the difference between instanceof and getClass()?"

• `instanceof` checks if an object is an instance of a specified class OR any of its derived subclasses.

• `getClass()` returns the EXACT runtime class of the object, rejecting subclasses.

Test Your Concept Mastery

Verify your retention on: Equality in OOP (== vs .equals), Method Hiding & String Immutability

Diagnostic Check
Question 1 of 1
Which of the following is mutable and thread-safe?
Ready for a full proctored assessment?

Take a free aptitude mock on a real company pattern, with a worked solution for every question.

Take an aptitude mock