If a class need multiple field information during object creation and also it is allowing fewer information.Than we have two option
1. Provide multiple constructor, or
2. Allow client to pass null argument while creating object.
Among these which is the best practice.
ex:
Case-1:
public class Test {
Test(A ob1,B ob2, C ob3){
}
Test(A ob1,B ob2){
this(ob1, ob2, null);
}
public static void main(String args[]){
Test ob = new Test(new A(),new B());
}
}
Case-2:
public class Test {
Test(A ob1,B ob2, C ob3){
}
public static void main(String args[]){
Test ob = new Test(new A(),new B(), null);
}
}
I have used main method in same class. Please consider these main methods in some other class.