joyalshark joyalshark - 10 months ago 44
Java Question

How to divide and implement two seprate classes using if statement

I was wondering is there any way we can implement two classes like below.

if(condition1){
do everything(methods and all)in Class1
}
else{
do everything(methods and all) in class2
}


I know how to do using each method using Class object. There will be something make easy to do things.

Answer Source

Your best bet would be to define an interface, with a method void doEverything().

This would then be implemented by Class1 and Class2.