Oop Sol
Oop Sol
---
**Department of CSE**
**Batch: 63**
**Section: All**
**Time: 01:30H**
---
### **1. a. Fundamental Paradigm Difference Between Structured Programming and Object-Oriented
Programming**
- **Structured Programming**:
- Examples: C, Pascal.
- **Object-Oriented Programming (OOP)**:
---
- **Reason**: Java avoids the "diamond problem" (ambiguity that arises when a class inherits from two
classes that have a common ancestor).
- **Alternative**: Java supports multiple inheritance through **interfaces**. A class can implement
multiple interfaces, allowing it to inherit method signatures from multiple sources.
---
- **Interface**:
- Can contain both abstract methods (without implementation) and concrete methods (with
implementation).
- Used to provide a partial implementation and define a common base for subclasses.
---
```java
class AREA {
}
public class Main {
```
---
- **Error**: The code has a syntax error due to extra closing braces (`}`) at lines 7 and 13.
- **Corrected Code**:
```java
diu.display();
class Daffodil {
void display() {
}
}
void display() {
```
- **Output**:
```
```
- Explanation: The `Department` class overrides the `display()` method of the `Daffodil` class, so the
overridden method in `Department` is called.
---
```
^ ^
| |
| |
+-------------------+ +-------------------+
| CheckingAccount | | SavingsAccount |
+-------------------+ +-------------------+
| + calculateInterest() | | + calculateInterest() |
+-------------------+ +-------------------+
```
```java
class Account {
this.accountNumber = accountNumber;
this.balance = balance;
this.accountType = accountType;
}
public void deposit(double amount) {
balance += amount;
balance -= amount;
} else {
System.out.println("Insufficient balance");
return balance;
deposit(interest);
}
// Customer class
class Customer {
this.customerID = customerID;
this.name = name;
this.address = address;
this.phone = phone;
if (accounts[i] == null) {
accounts[i] = account;
break;
if (account != null) {
// Main class
Customer customer = new Customer(1, "John Doe", "123 Main St", "555-1234");
customer.addAccount(savingsAccount);
customer.addAccount(checkingAccount);
savingsAccount.deposit(200);
savingsAccount.calculateInterest();
```
---