ATHENA
Java Programming Essentials / Smart Reader
THE ATHENA LIBRARY

Java Programming Essentials

Miriam Okafor · textbook

Chapter 5 · Classes and Objects

A class is a promise

Every Java program is assembled from classes. A class declares the fields an object will hold and the methods that act upon them. When we write new Account("Abeba", 500), the Java runtime allocates memory for a fresh object and runs its constructor to place it in a valid starting state.

It helps to think of a class as a promise made to the rest of the program: any object of this type will carry these fields and respond to these methods. The compiler checks that promise everywhere the type is used, which is why Java catches so many mistakes before a program ever runs.

Objects, in turn, are independent. Two Account objects share a blueprint but not a balance. Changing one leaves the other untouched — a simple fact that becomes the foundation for modelling complex systems.

A class describes what an object can be; an object is what the class becomes at runtime.

Fictional educational sample written for the Athena demo · Page 96 of 412.

25%saved