0% found this document useful (0 votes)
3 views

OOP ( Oriented Object Programming ) in JAVA

The document provides an overview of Object-Oriented Programming (OOP) concepts, including classes, objects, attributes, methods, and key principles such as polymorphism, inheritance, encapsulation, and abstraction. It explains how to declare and use classes in Java, along with examples of method overloading and overriding, as well as the role of constructors. Additionally, it presents a practical scenario of a Library Management System to illustrate the application of OOP concepts.

Uploaded by

anesboukhecha18
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
3 views

OOP ( Oriented Object Programming ) in JAVA

The document provides an overview of Object-Oriented Programming (OOP) concepts, including classes, objects, attributes, methods, and key principles such as polymorphism, inheritance, encapsulation, and abstraction. It explains how to declare and use classes in Java, along with examples of method overloading and overriding, as well as the role of constructors. Additionally, it presents a practical scenario of a Library Management System to illustrate the application of OOP concepts.

Uploaded by

anesboukhecha18
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 67

OOP

Dr Benabderrezak
Researcher in Cyber Security
Full-stack Web developer 1
OOP?

2
OOP ?

- A programming style that use classes & Objects to write codes


- A class is the blueprint
- The object is the real world example of a class

3
Class

Each class has 2 parts :

1. Attributes : are the properties or characteristics (like name , age , ..)

2. Methods : are the behaviors (like speak, run , eat , ..)

4
Class

5
How to declare Class in Java

6
How to use Class in Java ⇒ Create First Object

7
OOP Examples

8
First Program using JAVA + OOP

9
10
Program 2

11
Program 3

12
Program 4

13
Program 4

14
Getters & Setters

15
Getter
- A method used to retrieve the value of a private attribute

16
Setter
- A method used to set or update the value of a private attribute

17
18
Method overloading

19
Method overloading
When a class have multiple methods by same name but different parameters

20
Method overloading

21
Method overriding

22
Method overriding
When a subclass provides a specific implementation for a method in its parent
class.

23
Method overriding

24
Constructor

25
What is a Constructor in Java ?

- A constructor is a special method in a class that is automatically called when

an object of that class is created

- It is used to initialize the object's attributes when the object is instantiated.

26
27
28
29
OOP Concepts

30
OOP Concepts

There are 4 concepts :

1. Polymorphism

2. Inheritance

3. Encapsulation

4. Abstraction

31
Polymorphism : means many forms (same method but different use in each

subclass )

32
Inheritance :
Allowing classes to inherit common properties & methods from the parent class

33
Inheritance :

34
Inheritance :

35
Encapsulation
It refers to the bundling of data with the methods in a class

36
Abstraction

Display only the important informations by hiding the implementation

37
Abstraction

it is achieved through :

● Abstract classes

● Interfaces

38
Abstraction

Abstract classes

39
Abstraction - Abstract classes

- Classes that cannot be instantiated

- May contain both concrete and abstract methods

- A concrete method has a body (implementation)

- A abstract method does not have a body (no implementation)

40
Abstraction - Abstract classes

41
Abstraction - Abstract classes

42
43
Abstraction

Interfaces

44
Abstraction - Interfaces

- It only defines the methods, but it doesn’t say how they work

- The classes that implement the interface must provide the specific behavior

(method implementation)

45
Abstraction - Interfaces

46
Abstraction - Interfaces

47
Abstraction - Interfaces

48
Practical Scenario

49
Scenario: Library Management System

- The library has books with titles, authors, and availability status

- Members can borrow and return books

- Transactions keep track of borrowed books and their due dates

50
Scenario: Library Management System

Step 1: Define Classes and Relationships

1. Book : Represents a book with details like title, author, and availability

2. Member : Represents a library member who can borrow or return books

3. Transaction : Tracks borrowed books and due dates

4. Library : Manages books, members, and transactions

51
2. Book class :

52
2. Book class :

53
2. Book class :

54
3. Member Class :

55
4. Transaction Class

56
4. Transaction Class

57
5. Library Class

58
5. Library Class

59
5. Library Class

60
5. Library Class

61
6. Use the System in Main Program

62
6. Use the System in Main Program

63
6. Use the System in Main Program

64
6. Use the System in Main Program

65
66

You might also like