A object initializer executed two times because of inheritance concept ,right?
and secondly to say in one line initialization blocks are those that do not have main method ,suppose there are three classes in a program and one class would contain main so rest of the classes are initalization blocks??
bhavneet kaur
Ranch Hand
Joined: Apr 08, 2012
Posts: 32
posted
0
and also that are outside main
Kevin Florish
Ranch Hand
Joined: Jan 06, 2009
Posts: 155
posted
0
bhavneet kaur wrote:A object initializer executed two times because of inheritance concept ,right?
Indeed
bhavneet kaur wrote: and secondly to say in one line initialization blocks are those that do not have main method ,suppose there are three classes in a program and one class would contain main so rest of the classes are initalization blocks??
1) Initializer blocks can be static or non-static and are easy to spot as they have no name, just braces {} or static {}.
2) The main() method doesn't have to appear in your class at all. It is there so you can invoke other code from it, either using a command-line or some IDE to get things running.
3) If you have more than one class in your program, then generally you have a top-level class (nothing to do with main() method) and the other classes are some kind of nested class, but thats another topic