Skip to main content

Posts

Showing posts with the label Java Constructor| Constructor in Java

Java Constructors

Constructor A constructor is a special type of method of a class which is automatically called when the object of the class is been created. There are two types of constructor in Java programming language.. 1) Default Constructor. 2) Parameterized Constructor. Default Constructor default constructor also known as No argument constructor is a constructor in which no arguments are been passed, it is used to provide values to the object like 0,null, etc. depending upon the data type. Lets take an example of default constructor class defaultconstructor {        defaultconstructor()   // default constructor      {          System.out.println("Default Constructor is Invoked");      }      public static void main(String[] args)   // main method      {     defaultconstructor d1=new defaultconstructor(); // object is been created      } } Output Default Constructor is Invoked Explanation :- In the above example we have taken a class with name defaultconstructor in which we have taken