Originally posted by rajsim:
Hi Deekasha,
Thanks for explaining. But the thing that is puzzling me is this:
change
[b]public static void main
to
private static void main
It still works. I think this behaviour has something to do
with how the JVM executes the program.
[This message has been edited by rajsim (edited July 10, 2000).][/B]
This is very interesting!
It seems like the main method is just the entry point to the application. If you make it private in the base class, it is not accessible to the derived classes, but it is still available to the JVM. If you provide another main method in the derived class, public or private, that is the one that gets executed.
Example:
class abc{
int i = 017;
private static void main(String args[]){
System.out.println("Hello World!!" + i);
}
}
public class def extends abc{
int i = 20;
private static void main(String args[]){
System.out.println("Extended Hello World!!");
}
}
Here the main method from def is executed.
Savithri