Hot

Sharly

Friday, August 23, 2013

Constructors



A special method within a  class which gets  executed automatically at the time of creating the object. It is used  to store  initial values  within the objects instance variables. The name of the constructor is  same as the class’s name. A constructor is same as the class’s name. A constructor can not  return any values. It is called automatically when you create an object instance.


“this” Keyword

It is used to refer to the current object instance.

Instance variables
 Varibles that contain different values foreach object instance. An instance variable may be implemented as a primitive data type or as an object

Ex:

Public class student
            {
Instance variables
 
                        Private string name;                  
                        Private int marks;
                        …..
                        …..
            }


Student 1                                  Student 2
Name Sam                               Name Jane
Marks 80                                 Marks  90

Objects of student class




No comments:

Post a Comment