Hi,
I'm new yo java - apologies for silly questions. I'm getting a bit confused by the way classes are instantiated and called. In C++, to make use of a class I must create an instance of that class and then call methods within the class.
In Java, if for instance I have a class with a main method, I can run that code and the main method is run. However, I have not had to instantiate the class - is this done by the JVM?
In the example given on Suns website:
we look at an applet that responds to mouse events. We are told that the class must implement the mouslistner interface to work - fair enough. However, the neccesary methods seem to be called automatically - is this the JVM being helpful again?
Is the JVM doinjg al this instantiating and calling methiods as needed automatically 'behind the scenes' ?
Sorry for the enourmously long post,
Cheers,
Ben
I'm new yo java - apologies for silly questions. I'm getting a bit confused by the way classes are instantiated and called. In C++, to make use of a class I must create an instance of that class and then call methods within the class.
In Java, if for instance I have a class with a main method, I can run that code and the main method is run. However, I have not had to instantiate the class - is this done by the JVM?
In the example given on Suns website:
we look at an applet that responds to mouse events. We are told that the class must implement the mouslistner interface to work - fair enough. However, the neccesary methods seem to be called automatically - is this the JVM being helpful again?
Is the JVM doinjg al this instantiating and calling methiods as needed automatically 'behind the scenes' ?
Sorry for the enourmously long post,
Cheers,
Ben