Posts

Showing posts with the label Constructor

Constructor Overloading in Java

Constructor Overloading means when a class contain more than one method whose names are same as class name and parameter list is different . Here is an example .    public class ConstOverloadDemo    {        ConstOverloadDemo(String str)       {          System.out.print(str);       }      ConstOverloadDemo(String name ,int i)      {         System.out.print("Name : "+name+" , "+"Age : "+i);      }      public static void main(String[] args)       {           ConstOverloadDemo myObject = new ConstOverloadDemo("Constructor   Overloading : ");    ConstOverloadDemo myObject1 = new ConstOverloadDemo("Joes",25);   } } Output : Constructor Ov...

Constructor in Java

Constructor is a special type of method for create a instance of class. Constructor  name is same as class name . It has no return type . There are two types of constructor in java . These are a) Default Constructor b) Parameterized Constructor. Here is an example   Default Constructor :       public class ConstDemo       {          ConstDemo()           {             System.out.print("Default Constructor");           }          public static void main(String[] args)             {                 ConstDemo demo = new ConstDemo();              }  ...