Basically I have two classes Country and City. In city I have a method called getSize. I want to use this method in the Country class so I tried using this:
City c = City.getSize();
To store the method as a local variable but I either get an error about incompatible types or static methods?
You should do this if your method
getSizeis not static:And if the method is static then you can directly use it with the class name:
But I think you require first one as all city instance will have different size.
For the question :
To store the method as a local variableAnswer : You cannot do such thing in java. You should first create an instance of the class and then you can call the method using that instance any number of time you want.