TutorialsJavaCore Java
Share:

Core Java

intermediate

What You'll Learn

    Theory

    Java is fundamentally object-oriented. Understanding classes, objects, inheritance, and polymorphism is essential to writing effective Java code.

    Methods

    Methods define the behavior of objects. They consist of a signature (name, parameters, return type) and a body.

    public int add(int a, int b) {
        return a + b;
    }

    Methods can be overloaded — multiple methods with the same name but different parameter lists.

    Inheritance

    Inheritance allows a class to acquire the properties and methods of another class using the extends keyword:

    public class Animal {
        public void eat() { System.out.println("Eating..."); }
    }
    public class Dog extends Animal {
        public void bark() { System.out.println("Barking!"); }
    }

    OOP Principles

    • Encapsulation — Hiding internal state with private fields, exposing via public methods
    • Inheritance — Reusing and extending existing code
    • Polymorphism — Same interface, different implementations (method overriding)
    • Abstraction — Hiding complexity via abstract classes and interfaces

    Interfaces

    An interface defines a contract that implementing classes must fulfill. A class can implement multiple interfaces.

    Interface Example
    java

    Why this matters

    Object-oriented programming is at the heart of Java. Mastering inheritance, polymorphism, and encapsulation lets you write modular, reusable code that scales from small projects to enterprise systems.

    What's next

    In the next lessons, you'll dive deeper into each topic with hands-on examples and exercises.

    Exercises

    Vehicle Inheritance Hierarchy

    easy

    Create a Vehicle base class with speed and fuel fields, and a move() method. Create a Car subclass that adds a brand field and overrides move().

    Expected Output:

    Vehicle moving at 60 km/h\nCar brand Toyota moving at 120 km/h

    Mini Quiz

    Mini Quiz