LearnFrenzy
Sign in Take a free test

Java Programming · Topic 16 of 28

Object Class and Wrapper Classes

  • 4 exercises
  • 60 questions
  • ~60 min
  • Answers explained

Interview Questions

Object Class and Wrapper Classes · Study material

Java Object and Wrapper Classes – Interview Questions

1. Which class is the parent of all classes?

java.lang.Object.

2. Name the main methods of Object.

toString, equals, hashCode, getClass, clone, wait, notify, notifyAll and the deprecated finalize.

3. What is the contract between equals and hashCode?

If a.equals(b), then a.hashCode() == b.hashCode(); the reverse need not hold.

4. What happens if you override equals but not hashCode?

Equal objects land in different buckets, so HashSet stores duplicates and HashMap lookups fail.

5. == vs equals?

== compares references (or primitive values); equals compares content when overridden.

6. Why is getClass() final?

So that it always reports the true run-time class.

7. What does clone() do?

Creates a field-by-field (shallow) copy if the class implements Cloneable; otherwise throws CloneNotSupportedException.

8. Shallow vs deep copy?

A shallow copy shares referenced objects; a deep copy duplicates them too.

9. What is a marker interface? Example?

An interface with no methods that tags a class – Cloneable, Serializable.

10. What are wrapper classes?

Classes that wrap primitives in objects: Byte, Short, Integer, Long, Float, Double, Character, Boolean.

11. What is autoboxing?

Automatic conversion from a primitive to its wrapper (Integer.valueOf).

12. What is unboxing?

Automatic conversion from a wrapper to its primitive (intValue).

13. What is the Integer cache?

valueOf returns shared Integer objects for −128 to 127, so == may be true for small values only.

14. What happens when null is unboxed?

NullPointerException.

15. parseInt vs valueOf?

parseInt returns int; valueOf returns Integer (possibly cached).

16. Are wrapper classes mutable?

No; they are immutable and final.

17. Why use BigDecimal for money?

double uses binary fractions and cannot represent most decimals exactly; BigDecimal is exact.

18. BigDecimal equals vs compareTo?

equals also compares scale (0.30 ≠ 0.3); compareTo compares only the value.

19. Why does Long.valueOf(1).equals(1) return false?

1 is boxed to Integer, and Long.equals requires a Long.

20. What does Objects.requireNonNull do?

Throws NullPointerException (with an optional message) if the argument is null, otherwise returns it.

Ready to test your Programming?

Timed online tests with instant scores and explanations.

About this section

About Java Programming

Java is one of the most used languages in the world – for enterprise software, Android apps, banking systems and backend services. This section covers core Java from syntax and data types to OOP, strings, arrays, exceptions, collections and multithreading, with clear explanations and practice questions for every topic.

Why it matters

  • Java is the main language in service-company placement tests and many product companies
  • OOP, String, collections and exception questions appear in nearly every Java interview
  • Strong core Java is the base for Spring Boot, Android and backend development
  • Java questions are common in university exams and certification tests

Who it is for

  • School students (Class 11–12 / ICSE computer applications) learning Java
  • College students (B.Tech, BCA, MCA) preparing for exams, labs and projects
  • Freshers preparing for placements, Java developer roles and technical interviews
  • Developers revising core Java before an interview

What every topic gives you

  • Study material in five tabs: concepts with runnable examples, coding techniques, programs, interview questions and a cheat sheet
  • MCQs that check your understanding of every concept
  • "Predict the output" puzzles – the trickiest part of written tests
  • "Find the error" programs that train you to spot bugs quickly
  • Complete programs with solutions and real output, verified on a compiler

Asked in

  • Campus placements
  • Java developer interviews
  • Service company tests
  • University exams
  • Certification exams
  • Government IT exams

How to use this section

  1. Read the study material of a topic and run the examples yourself.
  2. Practise the four exercises – MCQs, output, errors, programs – and read every explanation.
  3. Test yourself with the timed online test, then revise the topics you got wrong.

Search LearnFrenzy

Esc

Quick links