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

Lecture11 OOPs Concept

class Account: - Initializes accounts with a private ID, balance, and interest rate - Allows checking the balance, withdrawing or depositing funds - Calculates monthly interest rate based on annual rate The Account class: - Stores ID, balance, and interest rate privately - Constructor initializes new accounts - getmonthlyinterestrate() returns monthly rate from annual rate - checkbalance() returns the account balance - withdraw() and deposite() allow modifying the balance Ten sample accounts are created with $100 and 4% annual interest. The user is prompted for an ID and can check balance, withdraw, deposit or exit

Uploaded by

kalpesh
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
25 views

Lecture11 OOPs Concept

class Account: - Initializes accounts with a private ID, balance, and interest rate - Allows checking the balance, withdrawing or depositing funds - Calculates monthly interest rate based on annual rate The Account class: - Stores ID, balance, and interest rate privately - Constructor initializes new accounts - getmonthlyinterestrate() returns monthly rate from annual rate - checkbalance() returns the account balance - withdraw() and deposite() allow modifying the balance Ten sample accounts are created with $100 and 4% annual interest. The user is prompted for an ID and can check balance, withdraw, deposit or exit

Uploaded by

kalpesh
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPT, PDF, TXT or read online on Scribd
You are on page 1/ 16

OOPS

IN
PYTHON
Instead of starting from scratch, you can
create a class by deriving it from a preexisting
class by listing the parent class in parentheses
after the new class name.
The child class inherits the attributes of its
parent class, and you can use those attributes
as if they were defined in the child class. A
child class can also override data members
and methods from the parent.
The Syntax is:
Overriding Methods

You can always override your parent class


methods. One reason for overriding parent's
methods is because you may want special or
different functionality in your subclass.
Example
class A:
def disp(self):
print ('A)

class B(A):
def disp(self):
print ('B)
super().disp()

class C(A):
def disp(self):
print( 'C)
super().disp()

class D(B,C):
def disp(self):
print ('D)
super().disp()

d = D()
d.disp()
Base Overloading Methods
Overloading Operators

Suppose you have created a Vector class to


represent two-dimensional vectors, what
happens when you use the plus operator to
add them? Most likely Python will yell at you.
You could, however, define
the __add__ method in your class to perform
vector addition and then the plus operator
would behave as per expectation
Example
Data Hiding

An object's attributes may or may not be


visible outside the class definition. You need
to name attributes with a double underscore
prefix, and those attributes then are not be
directly visible to outsiders.
Questions1(Account Class)
Design the class name account that contains:
A private id for account
A private balance for account
A private intrate for annual interest rate
A constructor that creates an account with specified id, initial balance and interest rate.
A method name getmonthlyinterestrate() that return monthly interest rate.
A method name checkbalance() that return balance amount from the account.
A method name withdraw() that withdraws a specified amount from the account.
A method name deposite() that deposits a specified amount to the account.
== Create 10 accounts with initial balance 100 and rate of interest 4%.
==The system prompts the user to enter account ID, if it is correct open a main menu having
chaises
1. Check balance, 2. withdraw, 3. deposit and 4. exit.

You might also like