aspose file tools*
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes  How Instance variables get Default values 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 " How Instance variables get Default values" Watch " How Instance variables get Default values" New topic
Author

How Instance variables get Default values

Ram Reddy
Ranch Hand

Joined: Feb 20, 2007
Posts: 88
Hi,

When the instance variables will be initialized to default values?

when the class is loading , then it will intialize all its instance variables with Default values ? These will be intialized in the Defalut constructor ?( Class has defalut constructor , which intializes all the instance variables , regardless of values assigned in class or not by using constuctor) ?
marc weber
Sheriff

Joined: Aug 31, 2004
Posts: 11343

Take a look at this article: Object Initialization in Java.


"We're kind of on the level of crossword puzzle writers... And no one ever goes to them and gives them an award." ~Joe Strummer
sscce.org
Ram Reddy
Ranch Hand

Joined: Feb 20, 2007
Posts: 88
hi marc,

My doubt is that , i have written one constructor to intialize the values

as

class Myclass
{
int var1;
int var2;
int var3 = 20;
Myclass(int v1, int v2)
{
varl= v1;
var2 = v2;
}

}

and i created object as

Myclass myclass = new Myclass(10,20);

for this object myclass values are var1 = 10 and var2 = 20, var3 = 30;

How many times values for var1 and var2 are intialized . Means , var1 and var2 ,var3 are initialized to default values(zero) when class is loaded.And after that var3 is intialized to 30 for myclass ?

please clarify me .

thanks in advance
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: How Instance variables get Default values