swraman
06-25-2009, 05:49 AM
Hi
Im new to Java. I have a question about classes in Java.
Im somewhat farmiliar with classes in PHP, and in PHP a class is defined, but it sits there and does nothing until a variable is declared to be an instance of that class.
In Java, this isnt the case, is it? In Java, a class is defined, and in the class there is a procedure:
public static void main (String [ ] args) {
which is executed when the program is run. Is this understanding correct?
This "public static void main(){}" is IN the class definition. So, isnt there a problem that when a new instance of the class is called in "public statc void main(){}" the instance of the class will have the main(){} method in it, and wont the main method in the newly created instance try to execute amain(){} again, and thus run into an infinite procedure?
Also, in java a constructor class is a method in the class that has the same name as the class, correct? and it is run at the time an instance of the class is created?
thanks
raman
Im new to Java. I have a question about classes in Java.
Im somewhat farmiliar with classes in PHP, and in PHP a class is defined, but it sits there and does nothing until a variable is declared to be an instance of that class.
In Java, this isnt the case, is it? In Java, a class is defined, and in the class there is a procedure:
public static void main (String [ ] args) {
which is executed when the program is run. Is this understanding correct?
This "public static void main(){}" is IN the class definition. So, isnt there a problem that when a new instance of the class is called in "public statc void main(){}" the instance of the class will have the main(){} method in it, and wont the main method in the newly created instance try to execute amain(){} again, and thus run into an infinite procedure?
Also, in java a constructor class is a method in the class that has the same name as the class, correct? and it is run at the time an instance of the class is created?
thanks
raman