OOPS in Java
OOPS in Java
G.Sidhartha 22D41A1223
K.Varsha Sri 22D41A1236
M.Sai venkat 22D41A1241
R.Ajay 22D41A1252
In Java, "Oops" typically refers to Object-Oriented
Programming (OOP) concepts. Java is a strongly
object-oriented language, and it implements key OOP
principles such as:
Classes and Objects: Classes in Java are blueprints
for objects. They define attributes (fields) and
behaviors (methods) that objects of that class can
exhibit.
Inheritance: Inheritance is a mechanism where a new class (subclass) can inherit properties
and behaviors from an existing class (superclass). This promotes code reusability and allows
for hierarchical relationships between classes.
Polymorphism: Polymorphism means the ability to take on many forms. In Java, polymorphism
is achieved through method overloading (compile-time polymorphism) and method overriding
(run-time polymorphism). It allows methods to behave differently based on the object that is
invoking them.
Encapsulation: Encapsulation refers to bundling the data (attributes) and methods that
operate on the data into a single unit (class). Access to the data is typically restricted to
methods of the class, which helps in hiding the internal state and protecting it from external
interference.
Abstraction: Abstraction focuses on the essential features of an object while hiding its
complex implementation details. In Java, abstraction is achieved through abstract classes
and interfaces. Abstract classes cannot be instantiated and may contain abstract methods
that subclasses must implement. Interfaces define a contract that implementing classes
must adhere to.
Inheritance:
Inheritance is a fundamental concept in Java and Object-
Oriented Programming (OOP) in general. It allows one class to
inherit properties and behaviors from another class,
promoting code reuse and establishing hierarchical
relationships between classes.
•Superclass (Parent Class): Also known as a base class or parent
class, it is the class being extended or inherited from.
•Subclass (Child Class): Also known as a derived class, it is the
class that inherits from another class (superclass).
Example syntax: class Subclass extends Superclass { .. }
Abstraction:
Abstraction in Java is a powerful concept used to simplify
complexity and manage software design effectively.
Abstract Class: An abstract class in Java is declared with the
abstract keyword. It can contain abstract methods (methods
without a body) that must be implemented by its subclasses.
Abstract classes cannot be instantiated directly; they are
meant to be extended by subclasses that provide concrete
implementations of the abstract methods.
Encapsulation:
Encapsulation in Java is a fundamental principle of object-
oriented programming that involves bundling the data
(variables) and methods (functions) that operate on the data
into a single unit, called a class. It helps in hiding the internal
state of an object from outside interference and manipulation.