Browse DevX
Sign up for e-mail newsletters from DevX

Tip of the Day
Language: Java
Expertise: Beginner
Dec 21, 2005

Overloading a Constructor or Method

Overloading a constructor or a method so it takes an extra argument based upon some specific requirement can result in duplicate code. For instance, a project that contains a lot of modules may have a requirement from a module to take to extra argument. To avoid this, pass "null" to the overloaded constructor:

Class Test {
	Test(String mgs){
		Test("data",null); // will call the Test(String mgs, Locale locale)
	Test(String mgs, Locale locale){

MV Prem Kumar
Thanks for your registration, follow us on our social networks to keep up-to-date