A Seminar On Object Oriented
Programming
POs:-Apply your knowledge of engineering to find solution.
Submitted By:-Amit Sahoo
Reg No.:-2201230008
Roll No.:-CS-22-118
•
Submitted To:-Mrs. Ipsita Panda
INDEX
• Introduction of OOPs
• Classes and objects
• Pillars of OOPS
• Advantages of OOPs
• References
Introduction of Object Oriented Programming?
• Object-oriented programming (OOP) is a programming paradigm
that uses the concepts of classes and objects.
Class is a logical construct which explains the structure and behavior
of an object.
Example: A Car class can have attributes like color and brand, and
methods like drive( ) and stop( ).
• An object has a physical existence; hence, it consumes memory.
• Once a class is designed, we can create any number of objects.
Four pillars of oops
• ABSTRACTION
• INHERITANCE
• ENCAPSULATION
• POLIMORPHISM
•
04/15/2025
Abstraction
Abstraction is a mechanism in Java that hides the background details and shows only the essential information.
• Example: • }
• abstract class A { • }
• abstract void Add(); • public class AbstractDemo {
• } • public static void main(String[]
• class B extends A { args) {
• public void Add() { • B aa = new B();
• int a = 10; • aa.Add();
• int b = 20; • }
• int c = a + b; • }
• System.out.println(c); • //output=30 5
Inheritance
• When one class accesses the properties of another class is called inheritance
Types of Inheritance
• 1. Single inheritance
• 2. Multilevel inheritance
• 3. Hierarchical inheritance
• 4. Hybrid inheritance
• Note Java does not support multiple inheritances at the class
level but can be achieved through an interface.
04/15/2025
Single Inheritance
In single inheritance, a sub-class is derived from only one super class. It inherits the properties and behavior of a
single-parent class. Sometimes it is also known as simple inheritance.
• class A {
• Int a=10; • int c = a + b;
• Int b=20; •
System.out.println(c);
• }
• }
• class B extends A {
• }
• public void Add() {
7
04/15/2025
Multilevel Inheritance
Multilevel inheritance is when a class inherits from another class, and then another class inherits from it.
This creates a chain where properties and methods are passed down through multiple levels.
• class D extends B {
• class A {
• public void addition() {
• int a = 50;
• int e = a + b + d;
• int b = 50;
• System.out.println(e);
• }
• }
• class B extends A { • }
• int d = 20; • public class Demo {
• public void add() { • public static void main(String[] args) {
• int c = a + b;
• D aa = new D();
• aa.add();
• System.out.println(c);
• aa.addition();
• }
• }
• }
• } 8
Hierarchical Inheritance
04/15/2025
• if a number of classes are derived from a single base class, it is called
hierarchical inheritance.
• class A { • int d = a - b;
• int a = 50;
• System.out.println(d);
• }
• int b = 50;
• }
• }
• public class Demo {
• class B extends A { • public static void main(String[] args) {
• public void add() { • B bb = new B();
• int c = a + b; • bb.add();
• System.out.println(c); • D aa = new D();
• aa.sub();
• }
• }
• }
• }
• class D extends A {
• // output=100
public void sub() {
9
• • //output=0
•
04/15/2025
Multiple-inheritances using interface
• In Java, an interface is a blueprint for a class that defines abstract methods (methods without a body)
that must be implemented by any class that uses the interface.
• interface A { • public void Print() {
• public void Show(); • System.out.println("Hello");
• } • }
• interface B { • }
• public void Print(); • public class Test {
• }
• public static void main(String[] args)
• class C implements A, B { {
• public void Show() { • C aa = new C();
• System.out.println("Hii"); • aa.Show();
• } • aa.Print();
• } 10
Polymorphism
• One entity many forms.
• The word polymorphism comprises two words, poly which means
many, and morph, which means forms
• In OOPs, polymorphism is the property that helps to perform a
single task in different ways.
• Let us consider a real-life example of polymorphism. A man at
the same time can be a father, teacher, brother, etc. Here,
a man is an entity having different forms.
04/15/2025
Method overloading
• Method overloading in java is a feature that allows a class to have more than one method with the same
name, but with different parameters.
• class Add {
• }
• void Add() { • public static void main(String[] args) {
• int a = 10, b = 20; • Add aa = new Add();
• int c = a + b; • aa.Add();
• System.out.println(c); • aa.Add(5, 5);
• } • aa.Add(5, 5, 5);
• void Add(int x, int y) { • }
• int z = x + y;
• }
• System.out.println(z);
• //output=30
• }
• //output=10
• void Add(int x, int y, int z) {
• //output=15
• int w = x + y + z;
12
Method Overriding
04/15/2025
Overriding in Java means defining a method in a child class that
already exists in the parent class with the same name, return
type, and parameters. This allows the child class to provide a
new version of the method.
• class Shape { • System.out.println("Square shape");
• void draw() { • }
• System.out.println("shape
• }
type"); • class Add {
• } • public static void main(String[]
args) {
• }
• Square aa = new Square();
• class Square extends Shape {
• aa.draw();
• @Override • }
• void draw() { • }
13
Encapsulation
• The act of putting various components together (in a capsule)
• In java, the variables and methods are the components that are
wrapped inside a single unit named class.
• All the methods and variables of a class remain hidden from any
other class.
• To achieve the encapsulation we have to use the access modifiers
(private,protected,default and public) restrict direct access.
Advantages of OOPs
• We can reuse code through the inheritance mechanism.
• It provides security, which we can achieve through
encapsulation and abstraction.
• It models a complex program into a simple structure.
References
Google :- www.geeksforgeeks.org/oops-concept-in-java/
Wikipedia:-https://en.wikipedia.org/wiki/Object-
oriented_programming
• Thank you