Title Slide • UnderstandingObject-Oriented Programming in Java – Part 1 • Presented by: [Your Name] • Institution: [Your Institution] • Date
2.
What is OOP? •Object-Oriented Programming (OOP) is a paradigm based on objects. • Real-world analogy: Car, Bank Account, Library Book. • Goal: Reusable and scalable components.
3.
Principles of OOP •Encapsulation: Wrapping data and code into one unit. • Inheritance: Derive new classes from existing ones. • Polymorphism: One interface, many implementations. • Abstraction: Hide internal details.
4.
Class and Objectin Java • Class: Blueprint of an object. • Object: Instance of a class. • Example: • class Car { • int speed = 0; • void accelerate() { • speed += 10; • } • }
5.
Encapsulation • Protects datafrom unauthorized access. • Use of private variables and public get/set methods. • Example: • class Student { • private int rollNo; • public void setRollNo(int r) { rollNo = r; } • public int getRollNo() { return rollNo; } • }
6.
Access Modifiers • public:Visible everywhere. • private: Within class only. • protected: Package & subclass. • default: Within package only.
7.
Constructors in Java •Called when object is created. • Can be overloaded. • Example: • class Book { • Book(String t) { title = t; } • }
8.
Case Study: BankAccount • Encapsulation and methods. • Example: • class BankAccount { • private double balance; • public void deposit(double amt) {...} • }