0% found this document useful (0 votes)
1 views31 pages

10- Object Oriented Programming Java(Lecture-10) ~500 11

Object-Oriented Programming (OOP) is a programming paradigm that organizes software design around data, or objects, rather than functions and logic, emphasizing concepts like abstraction, inheritance, polymorphism, and encapsulation. Classes serve as blueprints for creating objects, which are instances that contain attributes and methods, allowing for better structure and reusability in code. OOP offers advantages over procedural programming, such as faster execution, clearer program structure, and easier maintenance.

Uploaded by

kj.karim.jan01
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
1 views31 pages

10- Object Oriented Programming Java(Lecture-10) ~500 11

Object-Oriented Programming (OOP) is a programming paradigm that organizes software design around data, or objects, rather than functions and logic, emphasizing concepts like abstraction, inheritance, polymorphism, and encapsulation. Classes serve as blueprints for creating objects, which are instances that contain attributes and methods, allowing for better structure and reusability in code. OOP offers advantages over procedural programming, such as faster execution, clearer program structure, and easier maintenance.

Uploaded by

kj.karim.jan01
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 31

Object Oriented Programming (Java)

Classes & Objects


What is OOP?
• OOP stands for Object-Oriented Programming.
• Object-oriented programming has a sweeping impact because it appeals
at multiple levels and promises faster and cheaper development and
maintenance.
• The word object-oriented is the combination of two words
i.e. object and oriented.
• The dictionary meaning of the object is an article or entity that exists in
the real world.
• The meaning of oriented is interested in a particular kind of thing or
entity.
• In layman's terms, it is a programming pattern that rounds around an
object or entity are called object-oriented programming.
2
• The object-oriented programming is basically a computer programming
design philosophy or methodology that organizes/ models software
design around data, or objects rather than functions and logic.
• An object is referred to as a data field that has unique attributes and
behavior.
• It is the most popular programming model among developers.
• It is well suited for programs that are large, complex, and actively updated
or maintained.
• It simplifies software development and maintenance by providing major
concepts such as abstraction, inheritance, polymorphism,
and encapsulation. These core concepts support OOP.

3
• Procedural programming is about writing procedures or methods that
perform operations on the data, while object-oriented programming is
about creating objects that contain both data and methods.

4
OOP advantages over procedural programming
• OOP is faster and easier to execute
• OOP provides a clear structure for the programs
• OOP helps to keep the Java code DRY "Don't Repeat Yourself", and makes
the code easier to maintain, modify and debug
• OOP makes it possible to create full reusable applications with less code
and shorter development time

Tip: The "Don't Repeat Yourself" (DRY) principle is about reducing the
repetition of code. You should extract out the codes that are common for
the application, and place them at a single place and reuse them instead of
repeating it.

5
What are Classes and Objects?
• Classes and objects are the two main aspects of object-oriented
programming.
• A class is a template for objects, and an object is an instance of a class

6
7
Class
• A class is a blueprint or template of an object.
• It is a user-defined data type.
• Inside a class, we define variables, constants, member functions, and other
functionality.
• it binds data and functions together in a single unit.
• It does not consume memory at run time.
• Note that classes are not considered as a data structure.
• It is a logical entity.
• It is the best example of data binding.
• Note that a class can exist without an object but vice-versa is not possible.

8
Object
• An object is a real-world entity that has attributes, behavior, and
properties.

• It is referred to as an instance of the class.


• It contains member functions, variables that we have defined in the class.

• It occupies space in the memory.


• Different objects have different states or attributes, and behaviors.

9
10
• Everything in Java is associated with classes and objects, along with its
attributes and methods.
• For example: in real life, a car is an object.
• The car has attributes, such as weight and color, and methods, such as
drive and brake.

11
Create a Class

12
Create an Object
• To create an object of Main, specify the class name, followed by the
object name, and use the keyword new:

13
Multiple Objects
• You can create multiple objects of one class:

14
Using Multiple Classes
• You can also create an object of a class and access it in another class.
• This is often used for better organization of classes (one class has all the
attributes and methods, while the other class holds the main() method
(code to be executed)).
• Remember that the name of the java file should match the class name. In
this example, we have created two files in the same directory/folder:
• Main.java
• Second.java

15
Using Multiple Classes

16
Java Class Attributes
• Class attributes are basically variables within a class.
• Another term for class attributes is fields.

17
Accessing Attributes
• You can access attributes by creating an object of the class, and by using
the dot syntax (.):

18
Modify Attributes
• You can also modify attribute values:

19
• Or override existing values:

20
Final Keyword
• Final keyword will not allow to override existing values.
• The final keyword is useful when you want a variable to always store the
same value, like PI (3.14159...).

21
Multiple Objects
• If you create multiple objects of one class, you can change the attribute
values in one object, without affecting the attribute values in the other:

22
Multiple Attributes
• You can specify as many attributes as you want:

23
Java Class Methods
• Methods are declared within a class
• They are used to perform certain actions

24
Static vs. Public
• You will often see Java programs that have either static or public
attributes and methods.

• we create a static method, which means that it can be accessed without


creating an object of the class,
• unlike public method, which can only be accessed by creating objects

25
26
Access Methods With an Object

27
Java Constructors
• A constructor in Java is a special method that is used to initialize objects.

• The constructor is called when an object of a class is created.

• It can be used to set initial values for object attributes.

28
29
Access Modifiers
1) public The code is accessible for all classes

2) private The code is only accessible within the


declared class

3) protected The code is accessible in the same package


and subclasses.

4) default The code is only accessible in the same


package.
This is used when you don't specify a modifier.

30
Thank You…!

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy