| Author |
how this program works i didn't understand
|
Ritesh raushan
Ranch Hand
Joined: Aug 29, 2012
Posts: 97
|
|
output--hi
hi from m1
hi from main
|
 |
Jayesh A Lalwani
Bartender
Joined: Jan 17, 2008
Posts: 1263
|
|
Ritesh,
Please UseCodeTags while posting. I have added code tags for you
The static initializer of the class calls the constructor that calls m1. The static initializer is called as soon as the class is loaded, which happens before the main method is executed
|
 |
Jacob Morehouse
Greenhorn
Joined: Feb 22, 2012
Posts: 17
|
|
Hi Ritesh,
You have a couple things going on, I'll try to walk you through. First, spacing is goofy... makes it hard to for you to debug (using NetBeans, alt+shift+f will fix spacing).
This can't exist here, can't instantiate an object of the class from within the class:
You have to put that code in the main, like this:
Hope that helps,
Jake
|
 |
Darryl Burke
Bartender
Joined: May 03, 2008
Posts: 4163
|
|
Jacob Morehouse wrote:This can't exist here, can't instantiate an object of the class from within the class:
Yes you can, just so long as it's a static member. Attempting to unconditionally initialize an instance member or a constructor-local variable of the same type would lead to a StackOverflowError.
|
luck, db
There are no new questions, but there may be new answers.
|
 |
 |
|
|
subject: how this program works i didn't understand
|
|
|