Classes and Objects in Java Fundamentals of OOP

Download as pptx, pdf, or txt
Download as pptx, pdf, or txt
You are on page 1of 9

Classes and Objects in Java – Fundamentals of OOPs

• One of the main challenges that programmers face while writing


code is that while writing lengthy codes, the code becomes
haphazard and unorganized. It becomes very difficult to debug and
look for errors while checking them line by line. Here comes the
concept of OOPs programming which basically helps the
programmer organize the program in a proper way.
What are OOPs?

• OOPs stands for Object-Oriented Programming. As we all know


that Java is an Object Oriented Programming Language. OOPs
programming language tries to map our code with real-world
entities like objects, methods, inheritance, abstraction, etc, making
the code short and easier to understand. OOPs also makes our
programs easier to maintain and debug.
Advantages of Using OOPs:

• Reusability of code(DRY[Don’t Repeat Yourself] principle.)


• Data Hiding
• Privacy and Security to our code
• Low Maintenance cost
• High Readability
Main Principles of OOPS:

OOPs mainly consist of 6 principles:


• Class
• Object
• Abstraction
• Inheritance
• Polymorphism
• Encapsulation
There are few other sub principles of OOPs that we will discuss
at the end. They include:
• Coupling
• Cohesion
• Association
• Aggregation
• Composition
Classes in Java:

• A class is a logical entity or blueprint from which objects can be


created. A class can be described as a group of objects having
common properties. Classes in java contain: Fields, Methods,
Constructors, Blocks, Nested Classes and interfaces.
Objects in Java:

• An object is a real-life entity of a class. A class is a logical entity


whereas an object is a physical entity. A class is defined as a
template or blueprint, it is only when an object is declared that
memory is assigned to the program. An object has a proper state
and behaviour. Objects are also known as instances of a class.
Let us understand the relationship between
classes and objects with a real-world example:
• Suppose a student is filling an application form for an internship,
he will fill the form and send it to the company. Here the
application form is the class that contains fields like name, age,
gender, etc which are the contents of the class. After the student
fills the form, the final application of the student is known as the
object.
Program to understand the above
example:

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