Single logo
  • Courses
  • Blog
  • About
Join on SkoolJoin on Skool

In this topic

Java
  • Install Java 25 (JDK) and IntelliJ IDEA, Then Run Your First Program
  • Use Claude Agent, Copilot or Junie Inside IntelliJ IDEA
  • Java Hello World with Maven: What the JDK Does and What Maven Adds
  • Java Variables, Keywords and Naming Rules
  • Maven in IntelliJ: pom.xml, Dependencies and the Build Lifecycle
  • Java Primitive Types and Memory: What int x = 5 Really Does
  • Java Strings and Text Blocks: Quotes, Concatenation and parseInt
  • Java Operators: Arithmetic, a++ vs ++a, Precedence, && || and the Ternary
  • Java Type Casting: Widening, Narrowing and Converting Text to Numbers
  • Java Practice Lab: A Cafe Bill with Variables, Operators and Casting
  • Java if, else and switch: Braces, Else-If Ladders and the Modern Switch
  • Java Loops: for, while, do-while and for-each
  • Java break, continue and Nested Loops
  • What's New in Java 21 to 25: Compact Source Files and Sequenced Collections
  • Java Arrays: Indexes, Default Values, Loops and 2D Grids
  • Java Methods and Overloading: Parameters, return and Pass-by-Value
  • Java Scope, Code Blocks and the Call Stack
  • Read User Input in Java with Scanner (and the Leftover Enter Trap)
  • Java Practice Lab: A Gym Weekly Tracker with Loops, Arrays and Methods
  • Debugging Java in IntelliJ: Stack Traces, Breakpoints and a Better AI Prompt
  • Java var: Let Java Infer the Type
  • Push and Pull in IntelliJ: Two Developers, One GitHub Repository, a Rejected Push and a Conflict
  • Java Classes and Objects: One Blueprint, Many Cars
  • Java Constructors and the this Keyword
  • Java Instance Methods, Getters, Setters and toString
  • Java static: Fields, Methods and Blocks Shared by the Whole Class
  • Java Packages and Imports: Every Class Has an Address
  • Java Access Modifiers and Encapsulation: Private Data, Public Methods
  • Java final and Immutable Objects: Assign Once, Share Safely
  • Java Strings as Objects: The String Pool, == vs equals, StringBuilder and printf
  • Java Practice Lab: A Library Book Catalogue with final Fields and StringBuilder
  • Java Inheritance: extends, super and the Order Objects Are Built
  • Java Method Overriding, @Override and the Object Class
  • Java Polymorphism: Upcasting, Dynamic Dispatch and Downcasting
  • Java Composition: Has-A vs Is-A
  • Java Abstract Classes: A Parent That Leaves One Blank
  • Java Interfaces: Contracts and Multiple Inheritance
  • Java Nested, Inner and Anonymous Classes
  • Java Enums with Fields, Methods and switch
  • Java Practice Lab: Payment Processing with an Interface, an Abstract Class and an Enum
  • Java Records: A Whole Data Class in One Line
  • Java Sealed Classes and Interfaces
  • Java Pattern Matching with instanceof and switch
  • Java Record Patterns: Unpacking a Record
  • Java equals and hashCode: Why a HashSet Needs Both
  • From Arrays to Collections: The Java Collections Framework Map
  • Java Wrapper Classes and Autoboxing
  • Java ArrayList: The Stretchy Array
  • Java LinkedList vs ArrayList: Nodes or an Array
  • Java Sets: HashSet, LinkedHashSet and TreeSet
  • Java Sorting with Comparable and Comparator
  • Java Maps: HashMap, LinkedHashMap and TreeMap
  • Java Stacks, Queues and Deques: ArrayDeque and PriorityQueue
  • Choosing a Java Collection: Immutable and Sequenced Collections
  • Java Exception Handling: try, catch and finally
  • Java throw, throws, Checked vs Unchecked and Custom Exceptions
  • Java try-with-resources and Clean Error Handling
  • Java Generics: Type-Safe Containers
  • Java Generic Methods, Bounded Types and Wildcards
  • Java Lambdas and Functional Interfaces
  • Java Built-in Functional Interfaces: Predicate, Function, Consumer, Supplier
  • Java Optional: Saying Maybe Without null
  • Java Streams I: filter, map and reduce
  • Java Streams II: Collectors, groupingBy and flatMap
  • Why Concurrency: Processes, Threads and the Main Thread in Java
  • Creating Threads in Java: Thread, Runnable and Lambdas
  • Java Thread Lifecycle: sleep, join and interrupt
  • Java Race Conditions and synchronized
  • Java volatile and Atomic Variables
  • Java ExecutorService and Thread Pools
  • Java Callable, Future and CompletableFuture
  • Java Locks, Deadlock and tryLock
  • Java Concurrent Collections and Virtual Threads
  • Why Slow Work Belongs off the Request Thread: 202 Accepted and a Job Id in Spring Boot
  • Virtual Threads in Spring Boot: One Property, and the Connection Pool Trap
  • @Async, Named TaskExecutors and Structured Concurrency in Spring Boot
  • Java Files and Directories with NIO.2: Path and Files
  • Reading and Writing Text Files in Java
  • Java Structured Data: Reading and Writing JSON and CSV
  1. Blog
  2. /
  3. Java
  4. /
  5. Object-Oriented Programming

Java Abstract Classes: A Parent That Leaves One Blank

Employee is a job form with the monthly pay left blank. SalariedEmployee fills it as 60000 / 12 = 5000, HourlyEmployee as 120 x 25.5 = 3060, new Employee() won't compile, and one shared printPayslip() prints each employee's own pay.

Chaand Sheikh

·27 November 2026·Updated 28 November 2026Object-Oriented Programming

What you will learn

  • Declare an abstract class and an abstract method with no body
  • Fill the blank in each child class with @Override
  • Read the two compile errors: 'cannot be instantiated' and 'does not override abstract method'
  • Share a normal method in the parent that calls the abstract one

Before you start

  • Java inheritance: extends and super
  • Java polymorphism

Every employee has a monthly pay, but each kind of employee works it out differently. How do you make sure every child class writes that method? Make the parent abstract.

Think of the parent as a job form. The name is filled in for everyone. The monthly pay is left blank for each child to fill in its own way.

A class that is only a parent

package org.studyeasy.s03l14;

// A job form: the name is filled in, the monthly pay is left blank
public abstract class Employee {
    private final String name;

    public Employee(String name) {
        this.name = name;
    }

    public String getName() {
        return name;
    }

    // abstract: no body, just a semicolon. Every subclass must fill it in.
    public abstract double monthlyPay();

    // a normal method: written once, shared by every employee
    public void printPayslip() {
        System.out.println("Payslip: " + name);
        System.out.printf("  Pay: %.2f%n", monthlyPay());   // runs the object's own monthlyPay
    }
}
  • public abstract class: this class is only a parent. You can't create one with new.
  • The constructor is ordinary. Child classes call it with super(name).
  • public abstract double monthlyPay(); is a signature and a semicolon, with no body. Every class that extends Employee must write it.
  • printPayslip() is a normal method with a body, shared by all children.
The abstract Employee is a form: name filled in, monthlyPay blank. SalariedEmployee fills the blank with yearlySalary / 12, giving 5000 for Leah. HourlyEmployee fills it with hours times rate, giving 3060 for Jack. abstract Employee: name monthlyPay() = ____ SalariedEmployee yearlySalary / 12 → Leah 5000 HourlyEmployee hours x rate → Jack 3060
The parent fills what's the same; each child fills the one part that differs.

Children that fill the blank

package org.studyeasy.s03l14;

public class SalariedEmployee extends Employee {
    private final double yearlySalary;

    public SalariedEmployee(String name, double yearlySalary) {
        super(name);                  // Employee keeps the name
        this.yearlySalary = yearlySalary;
    }

    @Override
    public double monthlyPay() {      // fills in the blank
        return yearlySalary / 12;
    }
}
package org.studyeasy.s03l14;

public class HourlyEmployee extends Employee {
    private final int hours;
    private final double rate;

    public HourlyEmployee(String name, int hours, double rate) {
        super(name);
        this.hours = hours;
        this.rate = rate;
    }

    @Override
    public double monthlyPay() {      // same method, a different rule
        return hours * rate;
    }
}

Delete monthlyPay from SalariedEmployee and it won't compile: SalariedEmployee is not abstract and does not override abstract method monthlyPay() in Employee. The blank was never filled. Put it back and the error goes away.

One call, each employee's own rule

package org.studyeasy.s03l14;

public class Ex01_MonthlyPay {
    public static void main(String[] args) {
        Employee leah = new SalariedEmployee("Leah", 60000);
        Employee jack = new HourlyEmployee("Jack", 120, 25.5);
        System.out.println("Leah: " + leah.monthlyPay());   // yearly salary / 12
        System.out.println("Jack: " + jack.monthlyPay());   // hours * rate
    }
}
Leah: 5000.0
Jack: 3060.0

Both are held in Employee variables, and the same call gives two answers: 60000 / 12 = 5000, and 120 x 25.5 = 3060. This is polymorphism with a guarantee: every child is forced to have the method.

The parent can't be created

Add Employee temp = new Employee("Temp"); and Java says Employee is abstract; cannot be instantiated. A form with a blank isn't an employee. Create a child instead, as in the Leah line.

A normal method, shared by all

package org.studyeasy.s03l14;

public class Ex02_Payslips {
    public static void main(String[] args) {
        Employee leah = new SalariedEmployee("Leah", 60000);
        Employee jack = new HourlyEmployee("Jack", 120, 25.5);
        leah.printPayslip();    // shared steps, Leah's pay
        jack.printPayslip();    // same steps, Jack's pay
    }
}
Payslip: Leah
  Pay: 5000.00
Payslip: Jack
  Pay: 3060.00

printPayslip lives in Employee and is written once. Inside it, monthlyPay() runs the version that belongs to the object it was called on: SalariedEmployee's for Leah, HourlyEmployee's for Jack. The shared steps stay in the parent; the part that differs is in each child. The version is chosen while the program runs.

Recap

IdeaRemember
Abstract classonly a parent; new Employee(...) won't compile
Abstract methodsignature + semicolon, no body
Child classmust override every abstract method, or it won't compile
Normal methodhas a body, written once, shared by every child
Shared step calling the blankeach object runs its own version

When a class needs nothing but blanks, and you want a class to sign up to several of them, you'll use an interface instead.

Keep going in Java · 36 of 79

Previous
Java Composition: Has-A vs Is-A
Next post
Java Interfaces: Contracts and Multiple Inheritance
Community · Free to join
Single logo

StudyEasy AI Community

Hosted onSkool

Learn AI engineering, share what you build, and connect with other learners.

  • Free resources: lesson files, notebooks and code

  • Ask questions and join engineering discussions

  • Meet real people learning and building with AI

Join free on Skool

Related course on Udemy

FULL STACK JAVA : JAVA + JSP + SPRING BOOT AI + REACT + VIBE

Java 25, JSP, Hibernate, Spring Boot 4, REST APIs, React and Spring AI.View on Udemy ↗: FULL STACK JAVA : JAVA + JSP + SPRING BOOT AI + REACT + VIBE (paid course, opens in a new tab)

Related posts

Java Classes and Objects: One Blueprint, Many Cars

Six loose variables for two cars doesn't scale. A Car class is the blueprint; new builds each car with its own brand, speed and fuel. Plus field defaults, and why two variables can point at one car.

Java Constructors and the this Keyword

A constructor decides how an object is born: new Car("Toyota", 42.5) arrives filled in. this.brand vs brand, a second constructor that calls this(brand, 50.0), and why new Car() stops compiling once you write your own.

Java Instance Methods, Getters, Setters and toString

Give a Car class behaviour: accelerate() changes only this car's speed, private fields are reached through getSpeed and setSpeed, and toString turns Car@1b6d3586 into 'Toyota doing 60 km/h'.

Java static: Fields, Methods and Blocks Shared by the Whole Class

A static field lives once on the class: every Car ticks the same carsBuilt counter while keeping its own brand. Static methods need no object, a static block runs before main, and main is static so the JVM can start with no object.

On this page

  • A class that is only a parent
  • Children that fill the blank
  • One call, each employee's own rule
  • The parent can't be created
  • A normal method, shared by all
  • Recap
Community · Free to join
Single logo

StudyEasy AI Community

Hosted onSkool

Learn AI engineering, share what you build, and connect with other learners.

  • Free resources: lesson files, notebooks and code

  • Ask questions and join engineering discussions

  • Meet real people learning and building with AI

Join free on Skool

Related course on Udemy

FULL STACK JAVA : JAVA + JSP + SPRING BOOT AI + REACT + VIBE

Java 25, JSP, Hibernate, Spring Boot 4, REST APIs, React and Spring AI.View on Udemy ↗: FULL STACK JAVA : JAVA + JSP + SPRING BOOT AI + REACT + VIBE (paid course, opens in a new tab)

Single logo

Empowering Education, One Course at a Time

About
About usContact us
Legal
Terms of UsePrivacy Policy

© 2026 StudyEasy Organization. All rights reserved.