OOP · Building Blocks of OOP
Attributes vs Methods
Attributes – Describe the characteristics of the object.
Introduction
Every object in Object-Oriented Programming (OOP) is made up of two essential parts:
- Attributes – Describe the characteristics of the object.
- Methods – Define the actions the object can perform.
Together, attributes and methods represent the complete behavior of an object. What are Attributes? Attributes (also called fields, properties, or instance variables) represent the data stored inside an object. They describe the current state or characteristics of the object.
Student Example
- Name

- Age
- Roll Number
These values may vary from one student to another. What are Methods? Methods represent the behavior or actions that an object can perform. They define what the object is capable of doing.
Student Example
study()attendClass()payFees()
These methods describe the activities performed by a student. Why Do We Need Both? An object is incomplete without either data or behavior.
- Attributes tell us what the object has.
- Methods tell us what the object does.
Keeping both together inside a class is one of the fundamental principles of Object-Oriented Programming.


Attributes hold WHAT an object is; methods define WHAT it can do.
public class Employee {
// Attributes (fields) — the object's data / state
String name;
double salary;
// Methods — the object's behavior, often acting on its attributes
void raise(double percent) {
salary += salary * (percent / 100);
}
String describe() {
return name + " earns " + salary;
}
}