Hello,
I am working on a project and have become a little confused on how to
call methods from another class. Before I explain, here is an example:
class 0
{
main()
{
class 1 = new class1();
}
}
class 1
{
class1()
{
/*
now I want to call a method from class 0 (i.e.
class0.getVariable()) do I need to make a new instance or what since
this class already being called by class 0?
*/
}
}
Any idea? Also, class0 is a windows form and class1 is not, so calling
it again doesnt really make sense to me...
Thank you!
Tom
Arne Vajhøj - 20 Aug 2006 20:47 GMT
> I am working on a project and have become a little confused on how to
> call methods from another class. Before I explain, here is an example:
[quoted text clipped - 22 lines]
> Any idea? Also, class0 is a windows form and class1 is not, so calling
> it again doesnt really make sense to me...
The second class need a reference to the first class.
If the first class A do:
B o = new B(this);
and the second class B looks like:
public class B
{
private A a;
public B(A a)
{
this.a = a;
}
...
}
then other metods in B can call:
a.somemethod();
Arne
tomb - 20 Aug 2006 20:52 GMT
You can pass a reference to class0 to the constructor of class1, then
call class0 functions through the reference object.
class 1 = new class1(this);
T
>Hello,
>
[quoted text clipped - 30 lines]
>
>
Tom Machado - 20 Aug 2006 21:43 GMT
Perfect! Thank you for your help!