An embarassingly basic question.. Monday, 05-Jul-1999 12:53:06 129.97.36.6 writes:Here's a really trivial question that's been giving me grief for some time. I'm trying to access an instance method from the "main" class of an application (the one that instantiates all of the other classes).
I know that I have to reference an actual instance of the class in order to use an instance method (i.e. not the class itself, as I would for a static method), but since this is the top-level class, the instance is made only in the class itself (in the main() method). A static method won't do the job in this case (I'm using LiveConnect).
I'm very new to Java programming (or OO, for that matter), and I'm having a heck of a time trying to figure this one out. Can anyone lend a hand?
Brendan
Re: An embarassingly basic question.. Wednesday, 07-Jul-1999 12:12:24 12.29.40.3 writes:If I have got you write what you want is to access the non-static member functions of the class which has the main()?? what you can do is create an instance of this class within the main method and call the methods thru' this instance like..
public class a{
void x() {
System.out.println("hello") ;
}
static public void main(String d[]) {
a s = new a() ;
s.x() ;
}
}
Manish