0% found this document useful (0 votes)
64 views14 pages

Advanced Python Notes 14.05.2020

Here are the steps: 1. Define Employee class with __init__() method to initialize empno, ename, esal as instance variables 2. Define setEmpAge() method to validate and set empage instance variable 3. Define getEmpAge() method to return empage 4. Define DisplayEmpInfo() method to print emp details 5. Create Employee object obj and initialize with constructor 6. Call DisplayEmpInfo() to print emp details 7. Call setEmpAge() to set age by validating user input 8. Call getEmpAge() and print to display age So in summary: - Define Employee class with constructor and methods - Create object
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
64 views14 pages

Advanced Python Notes 14.05.2020

Here are the steps: 1. Define Employee class with __init__() method to initialize empno, ename, esal as instance variables 2. Define setEmpAge() method to validate and set empage instance variable 3. Define getEmpAge() method to return empage 4. Define DisplayEmpInfo() method to print emp details 5. Create Employee object obj and initialize with constructor 6. Call DisplayEmpInfo() to print emp details 7. Call setEmpAge() to set age by validating user input 8. Call getEmpAge() and print to display age So in summary: - Define Employee class with constructor and methods - Create object
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 14

OBJECT ORIENTED PROGRAM SYSTEM

-------------------------------
PROGRAMMING APPROACHES ARE TWO TYPES.

1)PROCEDURAL ORIENTED PROGRAMING APPROACH

WHAT IS PROCEDURAL ORIENTED PROGRAMING


THIS IS A COLLECTION OF FUNCTIONS (METHODS OR PROCEDURES)
STRUCTURE
M1()
{

}
M2()
{
}
MAIN()
{
M1()
M2()
}

EX: C

2) WHAT IS OBJECT ORIENTED PROGRAMING APPROACH


IN THIS APPROACH PROGRAM IS A COLLECTION OF CLASSES.
STRUCTURE OF OOPS
CLASS C1
{
M1()
{
}
M2()
{
}
CLASS C2
{
MAIN()
{
C1.M1()
C2.M2()
}}

Eg: C++,JAVA, PYTHON

OOPS PRINCIPLES

EVERY OBJECT ORIENTED PROGRAMING LANGUAGE FOLLOW THE FOLLOWING 4 PRINCIPLES

1) ENCAPSULATION
2) ABSTRACTION
3) INHERITENCE
4) POLYMORPHISM

class <classname>:
states
behaviours

what is state?
state represents some value
state can be variable or constant

what is variable
a state which represent some value but value can be chaged is called as variable

what is constant

what is state? Ans:- state represnts some value.. state can be variable or
constant..
what is variable? ANs: a state which represnt some value but value can be changed
is called as variable..

what is constant? state which represnt some value but value cant be changed is
called as constant..

types of variables
------------------
in python we have 3 types of variables

1) local varibale
2) instance variable
3) static varibale

1)A varibale which is declared within the function or method is called local
variables.
local varibales we can access only within that function.

Q)when memory will allocate for local variable


Ans)As part of method execution.

Q)when memory will deallocate for local varibale


Ans)once method execution completed.

2) Instance variable

when object created instance varibale generate

3)what is static variable..?


Ans: a variable which is declared inside the class or inside the static method by
prefixing class name is called as static variable..

Example to declar static variable

MyClass.a=10 when

static variable will get memrory?


Ans: .at the time of class is loading.
when static variable will destroy?
Ans: at the time of class is unloading..

note:
when we r declaring static variable with in class prefixing class name is
optional..but when r declaring static variable inside the static method prefixing
class name is compulosry..
what is Behvaiour?
Ans: .
->in python we can define 2 types of behaviours.
1)method or function or procedure.. 2)cosntructor..

what is method?
Ans: A behvaiour which represent some functionality, will execute when ever
programmer will call is called as method.

Types of methods
in python we will have 3 types of methods 1)instances method 2)static method
3)class method

what is instance method?


A method which is taking self keyword as first parameter is called as instance
method.
Instance method address will avilable within the object. Due to that reason
instance method we have to access by using object.

note : To define a method or a constructor in Python we should prefix def keyword.

Syntax to define instance method

def<method name(self)>:
<logic>

Types of construcotrs..
-----------------------------
constructors are two types..
1)default constructor or parameter less construcotr.
2)parameterized construcotor
----------------------------------------------
1)what is default constructor or parameter less construcotr.?
------------------------------------
Ans:
while defining a constructor..if we didn't declared any parameter except self
keyword.. which is called as default constructor..
----------------------------------------
<syntax to define default constructor>
---------------------------------------
def __init__(self):
<self.instance variablename>=<value>

Example to define Employee class by intializing empno,empname,empsal by using


defualt contructor..
------------------------------------------------
note:here for employee class
create two object..
one is emp1
two is emp2
---------------------------------------------------
what is parameteized construcotr?
------------------------------------
Ans:

task1
------------
define student class
states are:
----------------
stid
stname
stloc
behvaiours are:
-----------------
->parameterized constructor
->DisplayStudentInfo()
----------------------------
task2:
-------------------
define faculty class
states are:
------------------
fid
fname
fphno
behvaiours are:
------------------
->parameterized construcotr
->DisplayFacultyInfo()

7:54 PM: define Student..class


states.. are:
----------------
stid
stname
sttotmarks of m1,m2,m3
stavgmarks of m1,m2,m3
stresult of m1,m2,m3
------------------------------------------
behvaiours
--------------------
->parameterized consturcotr.
->CalResult(m1,m2,m3)
->Fail
if he got lessthan 35 in any one subject
i.e m1 or m2 or m3
->First class
if avgmarks>=60
->second class
if avgmarks>=50
->Third class
if avgmarks>=35
-
->DisplayStudentInfo()
stid
stname
sttotmarks
stavgmarks..
stResult..
-------------
7:13 PM: when we will go fofr local variable?
Ans:-
when every a field is required only
with in that method or constructor..
we will declare particular field
as local variable..
-------------------------------------------
when we will go for instance variable?\
Ans:
when ever a field is required for every object..
with the different value..
for example in Employee class
-------------------------------
empno
empname
empsal
--------------------------------------------
what is static varible?
Ans:-
a variable which we declared with in the
class or static method..
by prefixing class name..is called
as static varible..
note:-
for static varible when we r declaring
with in static method prefixing class
name is optional..
-------------------------------------

when we will go for local variable?


Ans:-
when every a field is required only
with in that method or constructor..
we will declare particular field
as local variable..
-------------------------------------------
when we will go for instance variable?\
Ans:
when ever

RN Reddy IT School (to All - Entire Audience):

7:14 PM: when we will go for instance variable?\


Ans:
when ever a field is required for every object..
with the different value..
for example in Employee class
-------------------------------
empno
empname
empsal
--------------------------------------------
what is static varible?
Ans:-
a variable which we declared with in the
class or static method..
by prefixing class name..is called
as static varible..
note:-
for static varible when we r declaring
with in static method prefixing class
name is optional..
-------------------------------------

Q: two completed sir

RN Reddy IT School (to All - Entire Audience):

7:13 PM: when we will go for local variable?


Ans:-
when every a field is required only
with in that method or constructor..
we will declare particular field
as local variable..
-------------------------------------------
when we will go for instance variable?\
Ans:
when ever a field is required for every object..
with the different value..
for example in Employee class
-------------------------------
empno
empname
empsal
--------------------------------------------
what is static varible?
Ans:-
a variable which we declared with in the
class or static method..
by prefixing class name..is called
as static varible..
note:-
for static varible when we r declaring
with in static method prefixing class
name is optional..
-------------------------------------

when we will go fofr local variable?


Ans:-
when every a field is required only
with in that method or constructor..
we will declare particular field
as local variable..
-------------------------------------------
when we will go for instance variable?\
Ans:
when ever

RN Reddy IT School (to All - Entire Audience):


7:14 PM: when we will go for instance variable?\
Ans:
when ever a field is required for every object..
with the different value..
for example in Employee class
-------------------------------
empno
empname
empsal
--------------------------------------------
what is static varible?
Ans:-
a variable which we declared with in the
class or static method..
by prefixing class name..is called
as static varible..
note:-
for static varible when we r declaring
with in static method prefixing class
name is optional..
-------------------------------------------------------------

RN Reddy IT School (to All - Entire Audience):

7:13 PM: when we will go for instance method\?


Ans:-
->when ever method functionality is depending on
atleast one instance variable..
then we will go for instance method..
---------------end------------------------
when we will go for static method?
Ans:-
->when ever method functionality is
not depening on any instance variable
we will define it as static method..
---------------------------------------

RN Reddy IT School (to All - Entire Audience):

7:18 PM: class MyClass:


compname="Wipro"
def __init__(self,eno,ename,esal):
self.empno=eno
self.empaname=ename
self.empsal=esal
def DisplayEmpInfo(self):
print("EmpNo is:",self.empno)
print("EmpName is:",self.empname)
print("EmpSAL is :",self.empsal)
print("company name is:",MyClass.compname)
def Greetings():
print("good morning")
======================================================

RN Reddy IT School (to All - Entire Audience):


7:23 PM: class Employee:
def __init__(self,eno,ename,esal):
self.empno=eno
self.empname=ename
self.empsal=esal
def setEmpAge(self,eage):
while eage<21 or eage>58:
eage=int(input("pls enter ur age between 21 to 58:"))
self.empage=eage
def getEmpAge(self):
return self.empage
def DisplayEmpInfo(self):
print("Employee No is:",self.empno)
print("Employee Name is:",self.empname)
print("Emplopyee salary is:",self.empsal)
obj=Employee(111,"rama",1000)
obj.DisplayEmpInfo()
myage=int(input("Enter ur age:"))
obj.setEmpAge(myage)
print("Employee age is:",obj.getEmpAge())
---------------------------------------------------------
RN Reddy IT School (to All - Entire Audience):

7:19 PM: what is inheritance?


Ans:-
inheriting the members from one class to another
class is called as inheritence..
->Estblishing parrent and child relation
between the classes is called as inheritence..
->a class which is giving is called as
parent class or super class or
base class
->a class which is reciving is called as
child class or sub class or derived class....
->because of inheritence super class members
can accessed by sub class but not vice verss
<syntax of inheritence>
-------------------------------
class BC:
//members
class DC(BC):
//MEMBERS
Types of inheritence
--------------------------------
in python we have various types of inheritence like below..
-----------------------------------------------------------
1)single inheritence
2)multiple inheritence
3)multi level inheritence
4)multi path inheritence
5)Hierarchal inheritence
6)Hybrid inheritence..
----------------------------------

RN Reddy IT School (to All - Entire Audience):

7:34 PM: Example 2 to impliment single inheritence..


-----------------------------------------------
BC
----------
states
-----------
self.a
self.b
behvaiours
--------------
->parameterized constructor
->DisplayBC(self)
-------------------
DC(BC)
-----------------
states
----------------
self.i
self.j
---------------------
behaviours
----------------
->prameterized constructor
->DisplayDC(self)

RN Reddy IT School (to All - Entire Audience):

7:56 PM: class BC:


def __init__(self,x,y):
self.a=x
self.b=y
def DisplayBc(self):
print("a value is:",self.a)
print("b value is:",self.b)
class DC(BC):
def __init__(self,m,n):
super().__init__(10,20)
self.i=m
self.j=n
def DisplayDc(self):
super().DisplayBc()
print("i value is:",self.i)
print("j value is:",self.j)
obj=DC(100,200)
obj.DisplayDc()
========================================================================

Q: single level inheritance

Q: one dept can contain more than one employee. But one employee may not belong to
more than one department..

RN Reddy IT School (to All - Entire Audience):

7:30 PM: Example to impliment single inheritence..


-------------------------------------------
Department
--------------------
states
--------------------
deptno
deptname
behaviours
-------------------
->parameterized constructor
->DisplauDeptInfo(self)
Employee(Department)
---------------------------
states
--------------
empno
empname
empsal
behaviours
----------------------
->parametrized cosntrucotr
->DisplayEmpInfo(self)..
=======================================================================

class Department:
def __init__(self,dno,dname):
self.deptno=dno
self.deptname=dname
def DisplayDeptInfo(self):
print("Department Number is:",self.deptno)
print("Department name is:",self.deptname)
class Employee(Department):
def __init__(self,eno,ename,esal):
super().__init__(111,'Technical')
self.empno=eno
self.empname=ename
self.empsal=esal
def DisplayEmpInfo(self):
super().DisplayDeptInfo()
print("Employee No is:",self.empno)
print("Employee Name is:",self.empname)
print("Employee Salary is:",self.empsal)
obj=Employee(111,'rama',1000)
obj.DisplayEmpInfo()
class Department:
def __init__(self,dno,dname):
self.deptno=dno
self.deptname=dname
def DisplayDeptInfo(self):
print("Department Number is:",self.deptno)
print("Department name is:",self.deptname)
class Employee(Department):
def __init__(self,eno,ename,esal):
sup
class Department:
def __init__(self,dno,dname):
self.deptno=dno
self.deptname=dname
def DisplayDeptInfo(self):
print("Department Number is:",self.deptno)
print("Department name is:",self.deptname)

8:21 PM: class Employee(Department):


def __init__(self,eno,ename,esal):
super().__init__(111,'Technical')
self.empno=eno
self.empname=ename
self.empsal=esal
def DisplayEmpInfo(self):
super().DisplayDeptInfo()
print("Employee No is:",self.empno)
print("Employee Name is:",self.empname)
print("Employee Salary is:",self.empsal)

obj=Employee(111,'rama',1000)
obj.DisplayEmpInfo()

8:24 PM: hw
task1
--------------
parrent class
Course
CHild class
student
task2:
---------------
parrent class
course
child class
faculty
task3:
------------------
parrent class
Shop
child class
customer
what is self?
Ans:
self is a keyword which represnt current
class object
super is a keyword.which rerepesnt super
class object
super() is using for
parrent class construcotr or instance method..

class BC:
def __init__(self,x,y):
self.a=x
self.b=y
def DisplayBcInfo(self):
print("a value is:",self.a)
print("b value is:",self.b)
class DC(BC):
def __init__(self,m,n):
super().__init__(10,20)
self.i=m
self.j=n
def DisplayDcInfo(self):
super().DisplayBcInfo()
print("i value is:",self.i)
print("j value is:",self.j)
class TC(DC):
def __init__(self,q,r):
super().__init__(100,200)
self.o=q
self.p=r
def DisplayTcInfo(self):
super().DisplayDcInfo()
print("o value is:",self.o)
print("p value is:",self.p)
obj=TC(1000,2000)
obj.DisplayTcInfo()
===================================

class Department:
def __init__(self,dno,dname):
self.dno=dno
self.dname=dname
def DisplayDeptInfo(self):
print("department no is:",self.dno)
print("department name is:",self.dname)
class Branch(Department):
def __init__(self,bid,bname):
super().__init__(10,'HR')
self.branchid=bid
self.branchname=bname
def DisplayBranchInfo(self):
super().DisplayDeptInfo()
print("branch id is:",self.branchid)
print("branch name is:",self.branchname)
class Employee(Branch):
def __init__(self,eno,ename,esal):
super().__init__(123,'Hyd')
self.empno=eno
self.empname=ename
self.empsal=esal
def DisplayEmpInfo(self):
super().DisplayBranchInfo()
print("Employee No is:",self.empno)
print("Employee Name is:",self.empname)
print("Employee salary is:",self.empsal)
obj=Employee(111,'rama',1000)
obj.DisplayEmpInfo()

8:24 PM: task1


University class
College class
Student clas
impliment multi level inheritence
task2
------------------------------------
University class
College class
Faculty clas
impliment multi level inheritence

You might also like