In order to access a public method exposed by another class, you must either:
1) Create an instance of that class in the area where you want to call it from (what you did to get it to work).
2) Make the method static, which means that you no longer need an instance, but are able to access the method by prefixing it with the class name.
An example of #1:
Code:
public class Math {} {
public int Power3( int x){
return (x*x*x);
}
}
public class A(){
private int y;
public int Get_Pow3 (int mmm){
Math MyMath = new Math();
y = MyMath.Power3(mmm);
}
}
There are numerous variations on this -- the MyMath variable could have had class scope instead of being declared in the method, it could have been passed in, it could have been inherited from a parent class, etc. But it all comes down to the idea that you need to create an instance of the Math class before making use of it.
An example of #2:
Code:
public class Math {} {
public static int Power3( int x){
return (x*x*x);
}
}
public class A(){
private int y;
public int Get_Pow3 (int mmm){
y = Math.Power3(mmm);
}
}
What happens here is that the Power3 method is shared amongst all instances of the Math class. You can call it from an instanced method within Math, but you cannot go the other way (a static method calling an instanced method) without an instance to operate on.
Using a static method is most useful when you have some small utility function that does not depend on it's class maintaining any state information. You'll see them used that way in the .NET framework, such as in the XmlConvert class.
Chip H.
____________________________________________________________________
If you want to get the best response to a question, please read FAQ222-2244 first