This week's book giveaway is in the Clojure forum.
We're giving away four copies of Clojure in Action and have Amit Rathore and Francis Avila on-line!
See this thread for details.
Win a copy of Clojure in Action this week in the Clojure forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

concept of objects

 
bhavneet kaur
Ranch Hand
Posts: 32
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator



output=main initializer
but when i dont create object output=main ??? how
can anyone explain
 
Enkita mody
Ranch Hand
Posts: 333
Firefox Browser Java Windows XP
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Object Creation
Initialization Blocks

-hth
 
bhavneet kaur
Ranch Hand
Posts: 32
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

i have read that link , as here there is no constuctor ,so a default constructor get created on creation of object which prints that initializer

 
Stuart A. Burkett
Ranch Hand
Posts: 679
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
bhavneet kaur wrote:
but when i dont create object output=main ??? how

You've answered your own question.
You don't create an object therefore the object initialiser is not executed.
 
bhavneet kaur
Ranch Hand
Posts: 32
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

it means whenever default costructor created it reads the whole program
 
dennis deems
Ranch Hand
Posts: 808
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
bhavneet kaur wrote:
it means whenever default costructor created it reads the whole program

No. It means that initialization blocks are executed only when something is instantiated.
 
Kevin Florish
Ranch Hand
Posts: 181
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
There is a bit more to initializer blocks, just to clarify them:

Say for instance we have classes A and B

Outputs:
A Object initializer
A Object initializer
B Object initializer

Because of the calls to 'super' when we instantaite a subclass.
 
bhavneet kaur
Ranch Hand
Posts: 32
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

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
Posts: 32
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
and also that are outside main
 
Kevin Florish
Ranch Hand
Posts: 181
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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

 
I agree. Here's the link: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic