Chaturmind
LearnDSASystem DesignBlogPremium
Sign inGet started
Chaturmind

Structured learning paths for engineers who want to go deep. Written by practitioners.

Learn

  • Java
  • DSA
  • System Design
  • Spring Boot
  • AI / ML

Company

  • Blog
  • Premium
  • Contact

Legal

  • Privacy Policy
  • Terms of Service

© 2026 Chaturmind. All rights reserved.

Built for engineers who want to go deep.


← Java Core Fundamentals

Object-Oriented Programming

  • Classes and Objects
  • Inheritance and Polymorphism
  • Interfaces and Abstract Classes

Collections Framework

  • List, Set, and Map
  • Generics

Exceptions & Best Practices

  • Exception Handling
  • equals() and hashCode()
  • String Manipulation
Chaturmind
← Java Core Fundamentals

Object-Oriented Programming

  • Classes and Objects
  • Inheritance and Polymorphism
  • Interfaces and Abstract Classes

Collections Framework

  • List, Set, and Map
  • Generics

Exceptions & Best Practices

  • Exception Handling
  • equals() and hashCode()
  • String Manipulation
HomeLearnJavaJava Core FundamentalsObject-Oriented Programming
✓ FreeBeginner· 8 min read

Classes and Objects

Understand how classes define structure and objects hold state.

Published January 15, 2025


Classes and Objects

In Java, a class is a blueprint that describes the structure and behaviour of objects. An object is an instance of a class — it holds concrete data.

public class BankAccount {
    private String owner;
    private double balance;

    public BankAccount(String owner, double initialBalance) {
        this.owner = owner;
        this.balance = initialBalance;
    }

    public void deposit(double amount) {
        balance += amount;
    }

    public double getBalance() {
        return balance;
    }
}

Creating Objects

BankAccount account = new BankAccount("Alice", 1000.0);
account.deposit(500.0);
System.out.println(account.getBalance()); // 1500.0

Key Concepts

  • Fields store an object's state
  • Methods define what an object can do
  • Constructors initialise the object when it's created
  • Encapsulation hides internal state with private and exposes behaviour through public methods

this keyword

this refers to the current object. Use it to disambiguate between a field and a parameter with the same name.

public void setOwner(String owner) {
    this.owner = owner; // this.owner = field, owner = parameter
}

Interview Tip

When asked about OOP, explain all four pillars: Encapsulation, Inheritance, Polymorphism, Abstraction. Use BankAccount as your go-to example — it naturally demonstrates encapsulation.

Next

Inheritance and Polymorphism

AI Tutor

Lesson: Classes and Objects

Quick actions

AI responses can be inaccurate. Verify critical information.