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

OOP Paradigm With Example

oop paradigm

Uploaded by

anee.cse8.bu
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)
11 views

OOP Paradigm With Example

oop paradigm

Uploaded by

anee.cse8.bu
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/ 4

Md Ahad

21-CSE-041
OOP Paradigm with Example

OOP: This is a process of optimizing programs by creating partitioned memory for object that
can be used many times as templates.
There are many languages which support OOP like - C++, Java, Python etc.

OOP has some important concepts:


● Class — These are collections of some variable and some method used in a specific
object.
class Student {
String firstName;
String lastName;
int height;
}

● Object — Part of a class, like variables and methods in a class.


public static void main(String[] args) {
Student Ahad = new Student();
Ahad.name = “Ahad”;
}

● Abstraction — It is considered as an extension of encapsulation. It hides the


implementation (code) details of the program.
abstract class Student{
public abstract void StudentCGPA();
void lateOrNot() {
System.out.println("Yes");
}
}
class Boys extends Student {
void getEarly() {
System.out.println("Yes");
}
}

● Polymorphism — It uses some methods in the same name to perform action in


different ways.
class Student {
public void lateOrNot() {
System.out.println("Students are late");
}
}

class Boys extends Student {


public void lateOrNot() {
System.out.println("Boys are late");
}
}

class Girls extends Student {


public void lateOrNot() {
System.out.println("Girls are late");
}
}

● Encapsulation — Wrapping variables, methods into a single class is called


encapsulation.
public class Student {
private String Sname; //
public getSName() {
return name;
}
public void setSName(String newName) {
this.name = newName;
}

● Inheritance — It is a way to create a subclass from a parent class (subclass from


another) where the subclass automatic accesses the methods and properties of the
parent class.
class Student {
protected String name = "Ahad";
public void home() {
System.out.println("Barishal");
}
}

class Boys extends Student {


private String BoysName = "Abtahi";
public static void main(String[] args) {
Boys firstBoys = new Boys();
firstBoys.home();
}
}

Pros of OOP:

1. It can be modified easily and implemented again.

2. It is difficult to maintain.

3. It can boost productivity of the program.

4. It contributes to creating high quality software.

Cons of OOP:

1. It is not always beginner friendly.


2. It produces a very big program size than other programs.
3. Its programs are slower than procedure based ones.
4. It is impossible to apply to all programming projects.

You might also like