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 ..
 
         PYTHON

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
         
 		pass

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")
p.names()

 

__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 ?

                       __del__

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 .



What is INHERITANCE  ?

           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()

p.child()

p.names("sathia")



Need to learn , types of INHERITANCE !!
Advertisements

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 )

Twitter picture

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

Facebook photo

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

Google+ photo

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

Connecting to %s