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

Java · Theory

Java Classes and Objects

← All stacks

Theory

28/270

Java Classes and Objects

A class is a blueprint. An object is a real thing built from that blueprint. The class Student describes what a student has (name, marks) and what a student can do (study). The class alone is not one student sitting in a bench. Only when you write new Student() do you get a real object in memory.

Let’s take this on the board. class Student { String name; void study() { System.out.println(name + " is studying"); } }. Then Student s = new Student(); s.name = "Asha"; s.study();. Output: Asha is studying. s is not the object. s is a remote — a reference — that points to the object on the heap. The heap is where objects live.

You can make two objects from one class: Student a = new Student(); Student b = new Student(); a.name = "Asha"; b.name = "Ravi";. Same blueprint, two people. Changing Asha’s name does not change Ravi. That is why we bother with objects instead of one global name variable.

null means the remote currently points to nothing. Student s = null; then s.study() crashes with NullPointerException. You pointed the remote at empty air and pressed a button. Always create with new (or get a real object) before you call a method.

Interview line, say it slowly: class = design, object = instance in memory via new. Don’t say “class and object are the same”. The class name Student does not store Asha’s marks. Only the object does.

Diagram
Class Student   (blueprint)
        │ new
        ▼
   s1 Asha          s2 Ravi
Exam tip

Say blueprint vs instance, then show Student s = new Student();

Example

class Student {
  String name;
}

public class Main {
  public static void main(String[] args) {
    Student s = new Student();
    s.name = "Asha";
    System.out.println(s.name);
  }
}

Java Classes and Objects — output: Asha. new Student() makes a real object; s.name is a field on that object.

Short notes

  • DefClass = blueprint. Object = real instance made with new.
  • RuleReference variable points to the heap object. null = no object.
  • RememberMany objects can come from one class.
  • TrapClass name is not the object. Class alone does not store one student’s data.

Questions

1

What is a class?

2

What is an object?

3

What is null?

4

Where does the object live?

Previous← Java Naming ConventionNextMethods 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.