aspose file tools*
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes about contructor Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of EJB 3 in Action this week in the EJB and other Java EE Technologies forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "about contructor " Watch "about contructor " New topic
Author

about contructor

Deedy Dee
Greenhorn

Joined: Mar 20, 2002
Posts: 13
what are member variable ?
what are instance variable?
Is "contructor initialize all the variable" correct?


-deedy
WiLL Tao
Ranch Hand

Joined: Dec 14, 2001
Posts: 56
Is "contructor initialize all the variable" correct?
the answer should be NO
Proved by code:
------------------------------
class TestConstructor
{
TestConstructor()
{
int a;
int b;
a=b;

}
public static void main(String[] args)
{
System.out.println("Hello World!");
}
}

-----------------------------
---------- javac ----------
TestConstructor.java:8: variable b might not have been initialized
a=b;
^
1 error
Normal Termination
Output completed (5 sec consumed).


Thank Folks who <b>Make Sense</b> here.<br />SCJP Platform 2
Varaku Venkata
Ranch Hand

Joined: Mar 17, 2002
Posts: 30
Originally posted by zhihui di:
what are member variable ?
what are instance variable?
Is "contructor initialize all the variable" correct?

member variable is one if it is a part of the class memeber like methods. constructors will not initialize these variables. and these variables should be initialized before use.
instance variable is one if it is a part of object. it is not declared as static. and all objects contain instance variables.
constructors initializes the instance variables if they are not initialized. (except in some cases like given above)
[ March 20, 2002: Message edited by: varaku ]
Valentin Crettaz
Gold Digger
Sheriff

Joined: Aug 26, 2001
Posts: 7610
varaku,
Welcome to Javaranch
Please read the Javaranch Naming Policy and change your publicly displayed name to comply with our unique rule. Thank you.


SCJP 5, SCJD, SCBCD, SCWCD, SCDJWS, IBM XML
[Blog] [Blogroll] [My Reviews] My Linked In
Valentin Crettaz
Gold Digger
Sheriff

Joined: Aug 26, 2001
Posts: 7610
Member variables are variables that are declared at the class level and not within methods or any other block declarations (initializers, etc).
Member variables are further separated into two groups: class variables and instance variables.
Class variables (or static fields) are those variables declared static. They are initialized when the class itself is initialized and it is the same variable for all instances of the class.
Instance variables are those variable not declared static. They are initialized everytime a new instance of the class is created just before the constructor is invoked.
Class and instances variables are assigned default values (4.5.5 Initial Values of Variables) when the class, respectively, the instance are initialized.
[ March 21, 2002: Message edited by: Valentin Crettaz ]
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
 
subject: about contructor
 
Similar Threads
certpal question
can a contructor be declared protected...
Protected Constructor
order of execution in java
Static variable initialization