Java Oop — Free Java Tutorial

Learn Java Oop in Java with a free, beginner-friendly tutorial, examples and practice for Indian students on Syllab.in.

Java Oop — Free Java Tutorial

Learn Java Oop in Java with a free, beginner-friendly tutorial, examples and practice for Indian students on Syllab.in.

✓ 100% Free ✓ No Login Needed ✓ NCERT / CBSE Aligned ✓ Download as PDF

TL;DR: Learn Java Oop in Java with a free, beginner-friendly tutorial, examples and practice for Indian students on Syllab.in.

Written & reviewed by the Syllab.in Academic Team (CBSE/NCERT subject experts) · Updated

🤖 Stuck on any question? Ask Syllab's free AI Tutor for a step-by-step explanation — instant, unlimited, no login.

Java Oop in Java

Object-Oriented Programming (OOP) is the foundation of Java. Everything in Java is organized around classes and objects.

A class is a blueprint or template. An object is a specific instance of that class created at runtime. For example, `Car` is a class; your specific red Honda Civic is an object.

Classes have fields (data/attributes) and methods (behavior). Fields store the state of an object; methods define what the object can do.

A constructor is a special method called when creating an object with `new`. It has the same name as the class and no return type.

The `this` keyword refers to the current instance of the class. It's used to distinguish between instance variables and constructor/method parameters with the same name.

Encapsulation is the practice of making fields `private` and providing `public` getter and setter methods to control access — protecting data integrity.

Java Oop — Syntax

public class ClassName {
    // Fields (private for encapsulation)
    private dataType fieldName;

    // Constructor
    public ClassName(dataType param) {
        this.fieldName = param;
    }

    // Getter
    public dataType getFieldName() { return fieldName; }

    // Setter
    public void setFieldName(dataType val) { fieldName = val; }

    // Method
    public returnType methodName() { ... }
}

// Create object
ClassName obj = new ClassName(value);

Learn Java Oop step by step with Syllab's free interactive Java tutorial — runnable code examples, practice exercises and instant AI feedback, all free with no signup. Explore the full Java course →