Class and Objects in Java
Programming
Introduction to OOP Concepts in Java
Your Name | Date
Introduction to Object-Oriented
Programming (OOP)
• • OOP is a programming paradigm based on
real-world entities.
• • Key principles:
• - Abstraction
• - Encapsulation
• - Inheritance
• - Polymorphism
What is a Class?
• • A class is a blueprint for creating objects.
• • It defines attributes (fields) and behaviors
(methods).
• • Syntax:
• class ClassName {
• // fields
• // methods
• }
Example of a Class in Java
• class Car {
• String brand;
• int speed;
• void display() {
• System.out.println(brand + " runs at " +
speed + " km/h");
• }
• }
What is an Object?
• • An object is an instance of a class.
• • Represents real-world entities.
• • Objects are created using the 'new' keyword
in Java.
Example: Creating Objects
• public class Main {
• public static void main(String[] args) {
• Car c1 = new Car();
• c1.brand = "BMW";
• c1.speed = 200;
• c1.display();
• }
• }
Constructors in Java
• • Special methods to initialize objects.
• • Same name as the class.
• • Types:
• - Default Constructor
• - Parameterized Constructor
• Example:
• Car(String b, int s) {
• brand = b;
Difference Between Class and
Object
• • Class → Blueprint, template.
• • Object → Instance of a class.
• Example:
• Class: Car
• Objects: BMW, Audi, Tesla
Memory Representation of Objects
• • Each object has its own copy of instance
variables.
• •Stack
Methods are shared among Heap all objects of the
class.
(Method calls, references) (Objects live here)
Advantages of Using Classes &
Objects
• • Reusability of code.
• • Modularity in programs.
• • Easier debugging and maintenance.
• • Promotes abstraction and encapsulation.
Conclusion
• • Class = Blueprint, Object = Instance.
• • Classes and Objects form the foundation of
Java OOP.
• • Essential for writing structured, reusable,
and maintainable code.
Q & A / Thank You
• Any Questions?
UML Class Diagram Example
Person
-----------
- name: String
- age: int
-----------
+ getName(): String
+ getAge(): int
+ setName(String): void
+ setAge(int): void