• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Bear Bibeault
  • Devaka Cooray
  • Liutauras Vilda
  • Jeanne Boyarsky
Sheriffs:
  • Knute Snortum
  • Junilu Lacar
  • paul wheaton
Saloon Keepers:
  • Ganesh Patekar
  • Frits Walraven
  • Tim Moores
  • Ron McLeod
  • Carey Brown
Bartenders:
  • Stephan van Hulst
  • salvin francis
  • Tim Holloway

How Instance variables get Default values  RSS feed

 
Ranch Hand
Posts: 88
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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) ?
 
Sheriff
Posts: 11343
Java Mac Safari
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Take a look at this article: Object Initialization in Java.
 
Ram Reddy
Ranch Hand
Posts: 88
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!