joyalshark joyalshark - 1 month ago 4
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

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

This would then be implemented by Class1 and Class2.