Python Programming - Classes - Discussion
Discussion Forum : Classes - General Questions (Q.No. 25)
25.
Consider the following Python code:
class BankAccount:
def __init__(self, balance):
self.balance = balance
def withdraw(self, amount):
self.balance -= amount
class SavingsAccount(BankAccount):
def __init__(self, balance, interest_rate):
super().__init__(balance)
self.interest_rate = interest_rate
def add_interest(self):
self.balance += self.balance * self.interest_rate
Which object-oriented principle is evident in the code?
Answer: Option
Explanation:
The code illustrates the concept of inheritance, where the `SavingsAccount` class inherits from the `BankAccount` class, inheriting its attributes and methods.
Discussion:
Be the first person to comment on this question !
Post your comments here:
Quick links
Quantitative Aptitude
Verbal (English)
Reasoning
Programming
Interview
Placement Papers