oop
oop
provided in both English and Urdu. The Urdu text is written in the local Urdu script.
English:
Object-Oriented Programming (OOP) is a programming paradigm based on the concept of "objects,"
which can contain data (attributes) and methods (functions).
Example in PHP:
class Car {
public $color;
public $model;
$this->color = $color;
$this->model = $model;
echo $car->displayInfo();
Urdu:
( آبجیکٹ اورینٹڈ پروگرامنگOOP) می ڈیٹا ایک پروگرامنگ رپیاڈائم ہ جو "آبجیکٹس" ےک تصور پر ی
مبن ےہ۔ ان ر ے
ے
(attributes) ( اور میتھڈزfunctions) شامل ہوت رہی۔
مثال:
class Car {
public $color;
public $model;
public function __construct($color, $model) {
$this->color = $color;
$this->model = $model;
echo $car->displayInfo();
English:
A class is a blueprint for creating objects, and an object is an instance of a class.
Example in Python:
class Person:
self.name = name
self.age = age
def greet(self):
print(person.greet())
Urdu:
( کالس ایک بلیو پرنٹ ہ جو آبجیکٹس بنا یinstance) ہ۔
اور آبجیکٹ ایک کالس یک ایک مثال،ن ےک رلی استعمال ہوتا ےہ ے ے
مثال:
class Person:
self.name = name
self.age = age
def greet(self):
print(person.greet())
English:
Inheritance is a mechanism where one class can inherit properties and methods from another class.
Example in Java:
class Animal {
void eat() {
void bark() {
dog.bark();
Urdu:
ے
طریق ( وراثت ایک میکانزم ےہ جس ےک ذریےع ایک کالس دورسی کالس یک خصوصیات اورmethods) می حاصل کر
وراثت ر
ے
سکن ےہ۔
مثال:
class Animal {
void eat() {
void bark() {
dog.eat();
dog.bark();
English:
Polymorphism allows objects to take multiple forms. It provides a way to perform a single action in
different ways.
Example in C#:
using System;
class Shape {
Console.WriteLine("Drawing a shape.");
Console.WriteLine("Drawing a circle.");
class Program {
shape.Draw();
Urdu:
کو مختلف شکلی اختیار ی
( پویل مورفزم ایک تصور ےہ جو اشیاءobjects) کرت یک اجازت دیتا ےہ۔ یہ مختلف طریقوں ےس ایک ر
ی
یہ عمل انجام دین کا طریقہ فراہم کرتا ےہ۔
مثال:
csharp
Copy code
using System;
class Shape {
public virtual void Draw() {
class Program {
shape.Draw();
5. What is Encapsulation?
English:
Encapsulation is the practice of keeping fields within a class private, then providing access to them via
public methods.
Example in Python:
python
Copy code
class BankAccount:
self.__balance = balance
def deposit(self, amount):
self.__balance += amount
def get_balance(self):
return self.__balance
account = BankAccount(1000)
account.deposit(500)
print(account.get_balance())
Urdu:
ے
رسائ عوایم ( انسکیپسولیشن کا مطلب ہ کہ کالس ےک اندر موجود فیلڈز کو پرائیویٹ رکھا جا ےpublic) میتھڈز ےک
ن اور ان تک ے
ن۔ذریےع فراہم یک جا ے
مثال:
python
Copy code
class BankAccount:
self.__balance = balance
self.__balance += amount
def get_balance(self):
return self.__balance
account = BankAccount(1000)
account.deposit(500)
print(account.get_balance())
6. What is Abstraction in OOP?
English:
Abstraction is the process of hiding the implementation details and showing only the essential
features.
Example in Java:
java
Copy code
void sound() {
System.out.println("Meow");
animal.sound();
Urdu:
دکھائ ے
جائ رہی۔ ے چھپائ ے
جائ رہی اور رصف یرصوری خصوصیات ے می تفصیالت ر
ابسییکشن وہ عمل ےہ جس ر
مثال:
java
Copy code
void sound() {
System.out.println(";)"میاؤں
animal.sound();
4o
You said:
ChatGPT said:
ChatGPT
Here’s an expanded list of Object-Oriented Programming (OOP) interview questions, examples, and
explanations with a focus on the four pillars of OOP. All examples are provided in English and Urdu.
1. Encapsulation ()انسکیپسولیشن
2. Inheritance ()وراثت
English:
Encapsulation is the concept of bundling data (fields) and methods (functions) that operate on the
data into a single unit (class). It restricts direct access to some components of the object to maintain
control over the data.
Example in Python:
python
Copy code
class Employee:
if salary > 0:
self.__salary = salary
def get_salary(self):
return self.__salary
employee.set_salary(55000)
print(employee.get_salary())
Urdu:
ے
رسائ کو می اکٹھا کرنا ےہ۔ یہ ڈیٹا ےک براہ راستانسکیپسولیشن کا مطلب ڈیٹا (فیلڈز) اور میتھڈز کو ایک واحد یونٹ (کالس) ر
کنیول برقرار ر ی
کھن ےک رلی استعمال کیا جاتا ےہ۔ محدود کرےک ر
مثال:
python
Copy code
class Employee:
if salary > 0:
self.__salary = salary
def get_salary(self):
return self.__salary
employee.set_salary(55000)
print(employee.get_salary())
English:
Inheritance allows a class (child class) to inherit attributes and methods from another class (parent
class). It promotes code reuse and establishes a parent-child relationship between classes.
Example in Java:
java
Copy code
class Vehicle {
void move() {
}
class Car extends Vehicle {
void drive() {
Urdu:
لین یک اجازت ے
دین ےہ۔ می ی(پینٹ کالس) یک خصوصیات اور میتھڈز وراثت ر
وراثت ایک کالس (چائلڈ کالس) کو دورسی کالس ر
ی
یہ کوڈ کو دوبارہ استعمال کرت ےک رلی اہم ےہ۔
مثال:
java
Copy code
class Vehicle {
void move() {
;)"یہ گاڑی حرکت ے
System.out.println("کرئ ےہ۔
void drive() {
}
}
English:
Polymorphism means "many forms." It allows one interface to be used for a general class of actions.
Polymorphism can be achieved using method overriding and method overloading.
Example in C#:
csharp
Copy code
using System;
class Shape {
Console.WriteLine("Drawing a shape.");
Console.WriteLine("Drawing a rectangle.");
}
}
class Program {
shape.Draw();
Urdu:
ی
کرت یک اجازت دیتا ےہ۔ پویل مورفزم کا مطلب "بہت یس شکلی" ہی۔ یہ ایک ر
انیفیس کو ے
کن مختلف کاموں ےک رلی استعمال ر ر
مثال:
csharp
Copy code
using System;
class Shape {
class Program {
shape.Draw();
English:
Abstraction is the process of hiding implementation details and showing only essential features to the
user. It can be achieved using abstract classes or interfaces.
Example in Java:
java
Copy code
void sound() {
System.out.println("Bark");
animal.sound();
}
Urdu:
کالرس یا ر
انیفیس ےک ی ر
ایبسییکٹ ر
ابسییکشن کا مطلب ےہ تفصیالت کو چھپانا اور رصف یرصوری خصوصیات کو ظاہر کرنا۔ یہ
ذریےع حاصل کیا جا سکتا ےہ۔
مثال:
java
Copy code
void sound() {
System.out.println(";)"بھونک
animal.sound();
Method Overloading:
English:
Creating multiple methods in the same class with the same name but different parameters.
Example in Python:
python
Copy code
class Calculator:
return a + b
return a + b + c
calc = Calculator()
Urdu:
ایک یہ کالس می ایک یہ نام ےک ساتھ لیکن مختلف پی ر
امییز ےک ساتھ متعدد میتھڈز بنانا۔ ر ر
مثال:
python
Copy code
class Calculator:
return a + b
return a + b + c
calc = Calculator()
Method Overriding:
English:
Redefining a method in a child class that already exists in the parent class.
Example in Java:
java
Copy code
class Parent {
void greet() {
void greet() {
parent.greet();
Urdu:
می پہےل ےس موجود ہو۔
می اس میتھڈ کو دوبارہ ڈیفائن کرنا جو رپینٹ کالس ر
ایک چائلڈ کالس ر
مثال:
java
Copy code
class Parent {
void greet() {
void greet() {
parent.greet();
4o
You said:
ChatGPT said:
ChatGPT
1. Class ()کالس
Example (Python):
python
Copy code
class Car:
self.brand = brand
self.model = model
def drive(self):
# Creating objects
car1.drive()
Urdu:
کالس ایک بلوپرنٹ ہ جو آبجیکٹس بنا ی
ن ےک رلی استعمال ہوتا ےہ۔ ے
2. Object ()آبجیکٹ
Example:
python
Copy code
Urdu:
آبجیکٹ ایک کالس کا انسٹینس ےہ جو اصل دنیا ےک وجود کو ظاہر کرتا ےہ۔
)کنسی ر
3. Constructor (کی ر
Example (C++):
cpp
Copy code
#include <iostream>
class Car {
public:
string brand;
string model;
brand = b;
model = m;
void display() {
cout << "Brand: " << brand << ", Model: " << model << endl;
};
int main() {
car1.display();
return 0;
}
Urdu:
کرت ےک وقت آبجیکٹس کو انیشالئز ی
کرت ےک رلی استعمال ہوتا ےہ۔ ی کنسی ر
کی ایک خاص میتھڈ ےہ جو کالس کو انسٹیٹ ر
1. Encapsulation ()انسکیپسولیشن
Example (Java):
java
Copy code
class BankAccount {
if (amount > 0) {
this.balance = amount;
return balance;
account.setBalance(5000);
Urdu:
کنیول یک ے
جائ ےہ۔ سیی ےک ذریےع ر
گیی اور ر ے
رسائ ر ی
جوڑت کا عمل ےہ۔ ڈیٹا تک انسکیپسولیشن ڈیٹا اور میتھڈز کو ایک ساتھ
2. Inheritance ()وراثت
• A mechanism to allow one class to acquire the properties and methods of another class.
• The parent class is called the base class, and the child class is called the derived class.
Example (C++):
cpp
Copy code
#include <iostream>
class Animal {
public:
void eat() {
};
public:
void bark() {
};
int main() {
Dog dog;
dog.bark();
return 0;
Urdu:
می استعمال کرنا۔
وراثت کا مطلب ےہ ایک کالس یک خصوصیات اور میتھڈز کو دورسی کالس ر
Example (C++):
cpp
Copy code
#include <iostream>
class Shape {
public:
};
public:
}
};
int main() {
shape->draw();
return 0;
Urdu:
پویل مورفزم کا مطلب ہ ایک ر
انیفیس ےک ذریےع مختلف اشکال کو ظاہر کرنا۔ ے
ر
4. Abstraction ()ابسییکشن
Example (Python):
python
Copy code
class Animal(ABC):
@abstractmethod
def sound(self):
pass
class Dog(Animal):
def sound(self):
print("Bark")
class Cat(Animal):
def sound(self):
print("Meow")
dog = Dog()
cat = Cat()
dog.sound()
cat.sound()
Urdu:
غی یرصوری تفصیالت کو چھپانا اور رصف یرصوری خصوصیات کو ظاہر کرنا۔ ر
ابسییکشن کا مطلب ےہ ر
• A relationship between two classes where one class uses the other.
2. Aggregation ()ایگریگیشن:
3. Composition ()کمپوزیشن:
• A strong form of aggregation where the contained object cannot exist independently of the
container.
o
کنسی ر
Urdu: کیز کا مقصد کیا ےہ؟ ر
o Urdu: می
او او یئ رthis کیورڈ یک اہمیت کیا ےہ؟
1. Banking System:
2. E-Commerce System:
3. Game Development:
4o
You said:
more
ChatGPT said:
ChatGPT
Here’s a deeper dive into Object-Oriented Programming (OOP), including more examples, practical
applications, and advanced topics in English and Urdu for better understanding.
Core OOP Features with Examples
1. Object ()آبجیکٹ
• Objects represent real-world entities and have states (attributes) and behaviors (methods).
Example (Python):
python
Copy code
class Car:
self.brand = brand
self.color = color
def drive(self):
# Creating objects
car1.drive()
Urdu:
آبجیکٹ کالس کا انسٹینس ہوتا ہ جو اصل دنیا یک ر ی
جیےس کار۔،چیوں کو ظاہر کرتا ےہ ے
2. Class ()کالس
• Example: A "Car" class defines attributes like brand and model and methods like drive.
Example (C++):
cpp
Copy code
#include <iostream>
using namespace std;
class Car {
public:
string brand;
string color;
void drive() {
cout << color << " " << brand << " is driving." << endl;
};
int main() {
Car car1;
car1.brand = "Honda";
car1.color = "Blue";
car1.drive();
return 0;
Urdu:
ن جا ے
ن رہی۔ کالس ایک ایسا ڈھانچہ ہ جس ےک ذریےع آبجیکٹس بنا ے
ے
1. Encapsulation ()انسکیپسولیشن
• Definition: Bundling of data and methods that operate on the data, restricting direct access.
• Scenario: A banking system where only authorized methods can modify an account's balance.
Example (Java):
java
Copy code
class BankAccount {
if (amount > 0) {
balance += amount;
return balance;
Urdu:
ے
رسائ کو محدود کرنا۔ انسکیپسولیشن کا مطلب ےہ ڈیٹا اور میتھڈز کو ایک ساتھ باندھنا اور ان تک براہ راست
2. Inheritance ()وراثت
• Definition: Allows a class to use the properties and methods of another class.
• Scenario: A vehicle class (parent) has properties like speed, which a car class (child) can inherit
and extend.
Example (Python):
python
Copy code
class Vehicle:
self.speed = speed
def display_speed(self):
super().__init__(speed)
self.brand = brand
def show_details(self):
print(f"Brand: {self.brand}")
self.display_speed()
car.show_details()
Urdu:
دین ےہ۔ ی
کرت ے وراثت ایک کالس کو دورسی کالس یک خصوصیات اور میتھڈز استعمال
• Scenario: Different payment methods (credit card, PayPal, etc.) in an e-commerce platform.
Example (Java):
java
Copy code
class Animal {
System.out.println("Cat meows");
myDog.sound();
myCat.sound();
Urdu:
ی
کرت یک اجازت دیتا ےہ۔ پویل مورفزم ایک ر
انیفیس ےک ذریےع مختلف طریقوں ےس کام
ر
4. Abstraction ()ابسییکشن
• Definition: Hiding complex implementation details and exposing only the essential features.
• Scenario: A user interacts with a car's steering and pedals without knowing the internal
mechanism.
Example (C++):
cpp
Copy code
#include <iostream>
class Vehicle {
public:
};
public:
};
int main() {
v->start();
delete v;
return 0;
Urdu:
غی یرصوری تفصیالت چھپانا۔ ر
ابسییکشن کا مطلب ہ رصف یرصوری ر ی
چییں دکھانا اور ر ے
1. Composition ()کمپوزیشن
Example:
python
Copy code
class Engine:
self.horsepower = horsepower
class Car:
self.brand = brand
self.engine = engine
engine = Engine(150)
Urdu:
کمپوزیشن کا مطلب ہ کہ ایک کالس دورسی کالس ےک آبجیکٹ کو شامل ے
کرئ ےہ۔ ے
2. Aggregation ()ایگریگیشن
Example:
java
Copy code
class Department {
String name;
Department(String name) {
this.name = name;
}
class University {
String universityName;
List<Department> departments;
this.universityName = universityName;
this.departments = departments;
Urdu:
ایگریگیشن ایک ہلکا کمپوزیشن ےہ جہاں شامل کردہ آبجیکٹ آزاد رہ سکتا ےہ۔
1. E-Commerce System:
2. Banking System:
3. Hospital Management:
4. Game Development:
Interview Questions