Ads Sponsored By Google :)

Wednesday, 23 January 2013

object|parameterized|copy constructor parameter in|for java with example|tutorial|program

object parameterized constructor  constructor with object parameter  object parameterized constructor in java object parameterized constructor in java example object parameterized constructor in java program
copy constructor in java  copy constructor in java with example copy constructor in java example
copy constructor in java tutorial example program for copy constructor in java

   Object Parameterized Constructor:

          A Constructor is said to be object parameterized if and only if it takes object as 
   By using this concept is to copy the content of one object into another object.
   The Concept of object parameterized constructor exactly similar to the concept of 
   copy constructor of C++.   In other words copy constructor concept doesnot support by java.but we can obtained the  
   functionality of copy constructor by using object parameterized constructor.
Object parameterized Constructor

    Following Program illustrates the concept of default overloaded and object  
    parameterized constructor.

      For Example:

       Class Consdemo2
         int a,b;
         Consdemo2()// Default Constructor
          System.out.println(“default parameterized Constructor”);
          System.out.println(“value of a”+a);
          System.out.println(“value of b”+b);
     Consdemo2(int x,int y)// Double Parameterized Constructor
        System.out.println(“double parameterized Constructor”);
         System.out.println(“value of a”+a);
         System.out.println(“value of b”+b);
      Consdemo2(Consdemo2 X)//Formal Parameter X Of Consdemo2 Class
        System.out.println(“Object parameterized Constructor”);
        System.out.println(“value of a”+a);
        System.out.println(“value of b”+b);

   Class MainDemo
     Public static void main(String args[])
     Consdemo2 c1=new Consdemo2(); 
     Consdemo2 c2=new Consdemo2(10,20);
     Consdemo2 c3=new Consdemo2(c2);//Object Parameterized  Calling constructor  Or We can call it as              
     //new Consdemo2(c2)


     In the above program Object c3 storing value that are stored in the Object c2 of values are  
    Consdemo2(Consdemo2  X) formal parameter of X of type ConsDemo2, then X it access  
   as X.a and X.b.

   Default parameterized constructor

  Double parameterized constructor

  Object parameterized constructor

No comments:

Post a Comment