As the title presumes, how do I this in Java? What im trying to do is something like this
first there is a class
public class MyFirstModel() {
//standard constructor
public MyFirstModel(){
//some lines of codes
}
//A method
public String getvalue() {
//do something then
return result;
}
}
And the second Model(class)
public class MySecondModel() {
//standard constructor
public MySecondModel(){
//some lines of codes
}
//A method
public String getvalue() {
//do something then
return result;
}
}
Having those two, sample, models i want to pass a class depending on the, action. Let’s just say there are two buttons and the first button is for the model and the second is for the second model. The third class that is to be pass to:
FinalClass fclass = new FinalClass(<class here>); <-- how do i pass the class here
Here, how do I pass the class? on the FinalClass, what would be its constructor? and how do I acces the methods of the passed class?
I hope you guys get what I mean. Please help.
You don’t want to have both models implement an interface?
MyModel.java:
MyFirstModel.java:
MySecondModel.java:
CallingClass.java:
Then you can construct MyModel however you want and pass it in to CallingClass.