Tuesday, 15 April 2014

What happens when you run java program?

Step 1 : Initially JVM looks for main() method in your java application. but as you know that 
              static Variables are initialized first.
Step 2 : Static blocks are get invoked.
Step 3 : Main method is invoked.
Step 4 : Constructor will be called when you create an object for the class.
Step 5 : Every default constructor has super(); as a first line. It calls its super class constructor.
Step 6 : If a program contain any Initialization block, then it is copied into the constructor 
             after super(); .
Step 7 : Statements are in the constructor will be executed.
Step 8 :User methods will be called using object of that class.

Sample Program :

program






















output
Output


No comments:

Post a Comment