Constructor Overloading Concept in Java
Constructor Overloading Concept in Java
As in java In addition to overloading methods, we can also overload constructors in java programming. Overloaded constructor is called based upon the parameters specified when new is executed.
When do we need Constructor Overloading?
Number of timer we need of initializing an object in different ways. This can be done using constructor overloading. For example, A Thread class has 8 types of constructors. If we do not want to specify anything about a thread then we can simply use default constructor of Thread class, however if we need to specify thread name, then we may call the parameterized constructor of Thread class with a String args like this:
Thread t= new Thread (" MyThread ");
post a comment