




















































































Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
This page cannot be seen from the preview
Don't miss anything!





















































































Introduction Object-Oriented Programming (OOP) is a programming paradigm. It organizes programs using objects. Objects represent real-world entities. OOP improves code reusability and security. (^) Java mainly follows OOP concepts.
(^) Encapsulation protects data. Abstraction hides implementation. Inheritance reuses existing code. Polymorphism provides many forms. These concepts improve software quality.
Abstraction Hides unnecessary implementation details. Shows only essential features. Simplifies program usage. Improves program maintenance. Achieved using abstract classes and interfaces. Syntax (^) abstract class Vehicle { abstract void start(); }
(^) Inheritance (^) Acquires properties from another class. (^) Promotes code reusability. (^) Reduces duplicate code. (^) Creates parent and child classes. (^) Uses extends keyword. Syntax (^) class Animal { } class Dog extends Animal { }
Advantages of OOP Improves code reusability. Provides better data security. Simplifies software maintenance. Models real-world objects. (^) Suitable for large applications.
Introduction Class is a blueprint. Object is an instance. Objects created from classes. Java uses classes extensively. Foundation of OOP concepts.
What is an Object? Real-world entity. Instance of a class. (^) Occupies memory during execution. Stores object data. (^) Accesses class methods. Object Creation Student s = new Student();
How Objects Work? Class defines properties. Object stores values. Methods perform operations. Multiple objects possible. Each object independent.
class Student { int rollNo = 101; String name = "Rahul"; void display() { System.out.println(rollNo); System.out.println(name); } public static void main(String args[]) { Student s = new Student(); s.display(); } }
Advantages of Classes and Objects (^) Organizes program efficiently. (^) Supports code reusability. (^) Simplifies software maintenance. (^) Models real-world entities. (^) Improves program readability.
Attributes Definition (^) Attributes are data members. (^) Store object properties. (^) Declared inside a class. (^) Also called instance variables. (^) Different objects store different values. Example (^) Name (^) Age (^) Roll Number (^) Department (^) Marks
Methods Definition (^) Methods define object actions. (^) Contain program instructions. (^) Perform specific tasks. (^) Can access attributes. (^) Improve code reusability. Example (^) display() (^) calculate() (^) login() (^) deposit() (^) withdraw()
Method Syntax General Syntax (^) returnType methodName() { // Statements } (^) Example (^) void display() { System.out.println("Welcome"); }
(^) class Student (^) { (^) String name = "Rahul"; (^) int age = 20; (^) void display() (^) { (^) System.out.println(name); OUTPUT (^) System.out.println(age); Rahul 20 (^) } (^) public static void main(String args[]) (^) { (^) Student s = new Student(); (^) s.display(); (^) } (^) }