• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

member variable in constructor doubt

 
Shiva Mohan
Ranch Hand
Posts: 486
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

In the above program,assigning �s� to �msg� before knowing the member variable �msg� declaration.How come the constructor inside msg=s is working without showing any compile error?when executing Line1,we didn�t know what type msg is?
 
Naseem Khan
Ranch Hand
Posts: 809
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Question is not which come first? Important thnig is the flow of controlat runtime.

When you call constructor, first msg is assigned default value. Since its type is String, it is assigned to null. Then after that constructor will explicitly set msg to s. So at that time, runtime system knows the type of msg.

Naseem
 
Neelesh Bodas
Ranch Hand
Posts: 107
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Forward Referencing
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic