What is a Class?
In Object-Oriented Programming (OOP), everything revolves around the idea of classes and objects. A class is the starting point , it acts as a template that defines what data and behaviours all objects of that type will share.
Class: A class is a blueprint or template that defines the attributes (data) and methods (behaviours) that objects created from it will have. No memory is allocated for data when a class is defined , it is purely a description.
Every class has two main components:
- Instance variables (attributes/fields) , represent the state of an object (e.g., a bird's species and age)
- Methods , represent the behaviours or actions an object can perform (e.g., a bird singing)
Think of a class like an architect's blueprint for a house. The blueprint describes the number of rooms, the layout, and the materials , but no actual house exists yet. You need to build a house from the blueprint before anyone can live in it.
In Java, the filename must match the class name exactly (e.g., Bird.java for class Bird). In Python, this is good practice but not enforced by the language.