Ads Sponsored By Google :)

Wednesday 23 January 2013

constructors in java use private types of using programming example|tutorial default|parameterized


constructors in java types of constructors in java  constructors in java example  use of constructors in java 
private constructors in java  constructors in java programming  using constructors in java constructors in java examples constructors in java tutorial examples of default constructors in java examples of private constructors in java examples of parameterized constructors in java parameterized constructors in java


     Constructors in java:
  
       A Constructor is Special member method which will be called by the JVM automatically  
   (implicitly) whenever   an object is created for placing our own values without placing default   
   values.
      The purpose of constructor is used to initialize the object.

       Advantages of  Constructor:

        1) It Eliminates in placing default values
        2) It Eliminates in calling ordinary methods explicitly.

       Rules / properities /characteristics of Constructor:

        While using constructors in our java program we need follow the rules as below:

         1)  Constructors will be called automatically whenever an object is created.

         2) Constructors names must be similar to class name.

         3) Constructors should not return any value even void also(if we write any type then   it   will    
             be treated as ordinary method).

         4)Constructors are not static (Because constructors will be called each every time as and   
           when an object is created) they belongs to instance in nature but not static.

         5) Constructors of one class cannot be inherited into another class because each 
            constructor is meant for initializing its own data members (i.e) each constructor is meant  
            for initializing its own data members.

         6) Private Constructor:(Usage)

           a) The access specifier of the constructor may or may not be private then the     
              corresponding class object must be created in the same class context but not in some  
              other class context.

           b) If modifier of not private then the corresponding class object can be created either in   
               same class context and in some other class context.

        Types of Constructors:
  
       1)      Default Constructor
       2)      Parameterized Constructor
    
       1)Default Constructor:

          Default Constructor in which it never takes any values or parameters.

          Syntax:

          Class <class-name>
       {
             ………..
            <class-name>()
          {
              //Block of statements……..
            }
          }

    2) Parameterized Constructor:
    
     A Constructor is said to be parameterized constructor if and only if it takes parameters.

Syntax:

   Class <class-name>
{
       ………..
     <class-name>(list of parameters)
   {
   //Block of statements……..
   }
  }




Object Parameterized Constructor:

     A Constructor is said to be object parameterized if and only if it takes object as parameter.   By using this
 concept is to copy the content of one object into another object.

For More Details.....





OverLoaded Constructor:

                     A Constructor is overloaded if and only if constructor name is same but its signature is different.

Here it would signature represents the following points.

a)  Number of parameters.

b) Order of Parameters.

c) Type of Parameters.


For More Details.......


Calling of a constructor overloaded constructor:
                    
             the communication that exists between current class constructor, base class constructor and  derived class constructor and also communication would exists between constructors of same class.

For More Details.....



No comments:

Post a Comment

LinkWithin