rankz_VtujUdhflsoFhdgp Constructor in Java - All type study material

Java programming

Java programming

About Me

my self - Harvendra Singh

Search This Blog

Sunday, February 9, 2020

Constructor in Java

Constructor - 



  • A constructor is special program which is use to create object often class. 
  • It is invoke using new keyword. 
  • It is use to the sign memory to new created object. 
  • The name of constructor is the name of class but there is no return datatype.

   Threre are many type of constructor :
  1. Default constructor
  2. Copy constructor 
  3. Argument constructor 

Default constructor
  • The simplest kind of constructor that a class can have is the one that has no parameter. 
  • When you do not explicity define a constructor for a class, then Java creats a default constructor for the class. 
  • The default constructor automatically initializes all instance variable.
General form - class name class-veriables (or)  object-name =new class name ()

Copy consructor -
  •   A copy constructor is a constructor that replicates (or) duplicates an existing object. So, it is called the copy constructor. 
  • It takes a parameter is a reference to an object of the same class to which the constructor depend. 

Examples- Triangle t1 = new triangle ();

Argument Constructor -

  • We cannot add always the above two numbers, so we need values to be added. The easy solution is to add parameter to the constructor. 
  • The default constructor is often sufficient for simple classes. It is not sophisticated ones. So, we need to declare the argument constructor, the default constructor is no longer used

        निवेदन - आपको यह पोस्ट पसंद आयी हो या आपकी
                  कोई सुझाव हो तो हमे comment के माध्यम 
                  से उल्लेख करे। और अपने दोस्तों के साथ                         Share करे।
   

No comments:

Post a Comment