aspose file tools*
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes member variable in constructor doubt Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "member variable in constructor doubt" Watch "member variable in constructor doubt" New topic
Author

member variable in constructor doubt

Shiva Mohan
Ranch Hand

Joined: Jan 05, 2006
Posts: 477

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

Joined: Apr 25, 2005
Posts: 809
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


Asking Smart Questions FAQ - How To Put Your Code In Code Tags
Neelesh Bodas
Ranch Hand

Joined: Jul 20, 2006
Posts: 107
Forward Referencing
 
 
subject: member variable in constructor doubt