D
dendeezen
How can I create an instance of a class in a static context?
I am a newbie, please point me the right direction.
My code looks like:
public Class1 {
// instance of another class
Class2 c2;
public Class1(Class2 c2) {
this.c2 = c2;
<code>
}
public static void main(String[] args, Class2 c2) {
//The next line is not allowed, I know , but what is
the solution?
this.c2 = c2;
Class1 c1 = new Class1(c2);
<code>
c1.setVisible(true);
}
}
I checked the books and surfed the net, but did not find the right
answer.
Thanks,
I am a newbie, please point me the right direction.
My code looks like:
public Class1 {
// instance of another class
Class2 c2;
public Class1(Class2 c2) {
this.c2 = c2;
<code>
}
public static void main(String[] args, Class2 c2) {
//The next line is not allowed, I know , but what is
the solution?
this.c2 = c2;
Class1 c1 = new Class1(c2);
<code>
c1.setVisible(true);
}
}
I checked the books and surfed the net, but did not find the right
answer.
Thanks,