To Study any object oriented programming language, that may be dynamic type language like python, ruby or static
type language like c++,java one has to learn/ask the following questions? If you are able to answer these
questions, then I think you can write object oriented programming in any programming language obviously that
should support the object oriented features. The questions are :-
How to create a class with the specific properties
Constructor
Destructor
Public, Private or Protected accee speicifer using instance method and properties
Static instance or properties
How to cretae a Object
Inheritance
Multiple Inheritance
Method overloading and method overridding
Special method of a class (Default base class and their inheritated method)
Operator Overloading
How to create a class with the specific properties
'''1. If the name of a Python function, class method, or attribute starts with (but doesn't end with) two underscores, It's private; everything else is public. Python has no concept of protected class methods (accessible only in theirown class and descendant classes). Class methods are either private (accessible only in their own class) or public (accessible from anywhere).'''classEmployee:empCount=0## public static variable__empC=0## private static varibale## constructordef__init__(self,name,salary):self.name=nameself.salary=salary## public state variableself.__privateField=4##private state variableEmployee.empCount+=1## public instance methoddefdisplayCount(self):print"Total Employee %d"%Employee.empCount## public instance methoddefdisplayEmployee(self):print"Name : ",self.name,", Salary: ",self.salary## private instance methoddef__private():print"private method is called"## private static method@staticmethoddef__static_method():print"I am a private static mehtod"## public static method@staticmethoddefstatic_method():print"I am a public static mehtod"## destructordef__del__(self):print"I am dieing"
How to cretae a Object
How to create the object and access the various properties and method
in python. we can undestand by using below example and I used the previous class
as base
123456
emp=Employee("XYZ",321)## creating object in pythonprintemp.salary## accessing public instance variableprintEmployee.empCount## accessing public static variableprintEmployee.static_method()## accessing public static methodprintemp.displayEmployee()## accessing public instance method printemp.__private()## Accessing private method, we get AttributeError