Topic outline

    • A function Object() { [native code] } is a block of codes that is identical to the method in Java. When an instance of the class is created, it is called. Memory for the object is allocated to the memory at the time of calling the function Object() { [native code] }. 


      It is a special kind of technique that is used to initialise the object. 


      At least one function Object() { [native code] } is named each time an object is generated using the new) (keyword. 

      If there is no builder available in the class, a default builder is named. In such instances, a default is given by the Java compiler.



      There are two types of builders in Java:

      1. no-arg constructor 

      2. parameterized constructor. 


      Note: It is called a function Object() { [native code] } since, at the time of object creation, it constructs the values. For a class, it is not appropriate to write a function Object() { [native code] }. This is because if your class does not have any, the Java compiler generates a default function Object() { [native code] }.


      For the function Object() { [native code] }, there are two rules described. 


      The name of the builder must be the same as his class name. 

      A builder must not have an explicit return form, 

      An abstract, static, final, and synchronised Java function Object() { [native code] } can not be possible. 


      Java Default Constructor


      A constructor is called "Default Constructor" when it doesn't have any parameter.

      Syntax of default constructor:


      <class_name>(){}


      Java Parameterized constructor 


      A parameterized function Object() { [native code] } is called a function Object() { [native code] } that has a particular number of parameters. 


      Why use a parameterized constructor? 


      The parameterized function Object() { [native code] } is used to provide distinct objects with different values. You can, however, also have the same values.


      Example- 


      package examples;

      class constructor_test{

      //default constructor

      constructor_test()

      {

      System.out.println("Default Constructor");

      }

      //parameterized constructor

      constructor_test(String str)

      {

      System.out.println("Parameterized Constructor with parameter = " + str);

      }

      }


      public class constructors_example 

      {

      public static void main(String[] args)

      {

      //calling default constructor

      constructor_test dcons = new constructor_test();

      //calling parameterized constructor

      constructor_test pconst = new constructor_test("Name");

      }

      }


       Constructor overloading in Java 


      A function Object() { [native code] } is just like a technique in Java, but without a return type. Like Java techniques, it can also be overloaded. 


      In Java, builder overloading is a method of making more than one builder with different lists of parameters. They are structured in a way that a different task is performed by each function Object() { [native code] }. The compiler distinguishes them by the number of parameters in the list and by their types.