Learning OOPS concept .. Will keep updating !!!!

Hi friends , today I attended one interview .. They asked 

about some OOPS concept ,

I was little confused .. so I plan to Update concept

 of OOPS at time when I am free ..

Today I learnt about          “what is __init__ ?”

Why __init__ ? What is __init__ ?

“init” means initialisation !!!

Eg .. normal method of class withou using __init__

class value : //creating a class

v = value() //creating object 

v.x = 3.0 // object has two co-ordiantes x and y

v.y = 4.0

Instead u can give value like this :

class value : 

         def __init__(self,x,y):
                  self.x = x
                  self.y = y

v =value(3,4) 

 __init__ means instantiation

Simple program to understand class and object :-

class person :
         def __init__(self,x):
               self.x = x 
         def names(self):
                print "My name is " , self.x

p = person("sathia")


__init __ is first method in a class , which is called as “class constructor” and it is also called as 

initialization method that Python calls when you create a new instance

  You declare other class methods like normal functions with the exception that the first argument to each method is self. Python adds the self argument to the list for you; you don't need to include it when you call the methods.

     Self here denotes object “p” 
 Now u know what is class constructor ? 

 (i.e) … now what is class destructor ?


Whai is class variable ?

                  Class variable whose value would be shares among all instance of this class .. This variable 

can be accessed as “classname.variable”  (eg. Student.marks) from ousite and inside class .


           Acquiring one class propreties to another class .. (i.e) getting base class properties to derived class .

       EG . 

class person :

        def __init__(self):

              print "hi this is parrent constructor !!"

         def names(self,x):

               self.x= x

               print "name is ", self.x 

class student(person):
  //inherit properrty of class person into student

           def child(self):

                print "this is child method "

p = student()



Need to learn , types of INHERITANCE !!

About sathia

Web developer at cloudmint
This entry was posted in programs. Bookmark the permalink.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s