SteelReed

Search

Search posts, questions…

OOP & DesignQuestion 1 / 42

Junior

What is the difference between a class, an object and a constructor in Java?

Short answer

A class is a blueprint; an object is one concrete instance on the heap with its own state. A constructor runs on new: same name as the class, no return type, not inherited.

newno constructor declaredClass: blueprintConstructor runsObject 1 on heapObject 2 on heapCompiler addsdefault constructor

3 points to say:

  1. One class creates many objects.
  2. A constructor has no return type.
  3. Declaring a constructor with parameters removes the default one.

Keep reading the deep dive

Create a free account to read the full explanation and follow-up questions, mark questions as studied and review them on a schedule.