0% found this document useful (0 votes)
8 views5 pages

OOPs DSA Notes Full

The document provides an overview of Object-Oriented Programming (OOP) concepts including classes, objects, access modifiers, getters and setters, encapsulation, and constructors. It includes Java code examples to illustrate these concepts and highlights the benefits of encapsulation such as data hiding and improved code maintainability. Additionally, it explains different types of constructors used for object initialization.

Uploaded by

sinhbaradj
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)
8 views5 pages

OOPs DSA Notes Full

The document provides an overview of Object-Oriented Programming (OOP) concepts including classes, objects, access modifiers, getters and setters, encapsulation, and constructors. It includes Java code examples to illustrate these concepts and highlights the benefits of encapsulation such as data hiding and improved code maintainability. Additionally, it explains different types of constructors used for object initialization.

Uploaded by

sinhbaradj
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/ 5

### Object-Oriented Programming (OOPs) - DSA Notes

---

1. **Classes & Objects**

- **Class**: A blueprint for creating objects. It defines properties (fields) and methods (functions).

- **Object**: An instance of a class containing data and behavior defined by the class.

**Example (Java):**

```java

class Car {

String brand;

int speed;

void display() {

System.out.println("Brand: " + brand + ", Speed: " + speed);

public class Main {

public static void main(String[] args) {

Car car = new Car();

car.brand = "Tesla";

car.speed = 200;

car.display();

}
}

```

---

2. **Access Modifiers**

Control access to members of a class:

- `public`: Accessible everywhere.

- `private`: Accessible only within the class.

- `protected`: Accessible within the package and by subclasses.

- Default (no modifier): Accessible within the package.

**Example:**

```java

class Car {

private String brand;

public int speed;

public void setBrand(String brand) {

this.brand = brand;

public String getBrand() {

return brand;

```
---

3. **Getters & Setters**

Used to access and modify private fields.

**Example:**

```java

class Student {

private String name;

public void setName(String name) {

this.name = name;

public String getName() {

return name;

```

---

4. **Encapsulation**

Wrapping data and methods in a single unit (class) and restricting direct access to fields.

**Benefits:**

- Data hiding.
- Improved code maintainability.

---

5. **Constructors**

Special methods used to initialize objects.

- **Default Constructor**: No arguments.

- **Parameterized Constructor**: Takes arguments.

- **Copy Constructor**: Initializes an object by copying another object.

**Example:**

```java

class Car {

String brand;

// Default Constructor

Car() {

brand = "Unknown";

// Parameterized Constructor

Car(String brand) {

this.brand = brand;

```
... (Further sections are included in the PDF)

You might also like