So lets say i have 2 types of objects, and I won't know ahead of time which object will be used. I want too apply whichever object is used to do the same things in a specific method. How can i do this without duplicating code?
ex:
if (input=1){
version1 version = new version1()
}
else{
version2 version = new version2()
}
**do something with version**
obviously this way won't compile, but what would i need to do to accomplish what i am trying to achieve?
Maybe I have to do a try catch? sorry I am still new to java.