aspose file tools
The moose likes Mock Exam Errata and the fly likes default value? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Groovy Fundamentals video training course this week in the Groovy forum!
JavaRanch » Java Forums » Certification » Mock Exam Errata
Bookmark "default value?" Watch "default value?" New topic

default value?

jordan gong
Ranch Hand

Joined: Jun 12, 2001
Posts: 37
Can a local uninitialized(only declared) object get the default value?
Snylt Master
Ranch Hand

Joined: Jul 07, 2001
Posts: 55
I dunno! I tried the following and got compile error:

public class Q21 {
public void aMethod(){
Q21 newQ21;

System.out.println( newQ21 ); // Variable newQ21 may not have been initaialized.
public static void main(String[] args) {
Q21 anotherQ21 = new Q21();

Soo...According to the code above you must use the [ new ] statement to compile the code. andyou will get something like this
// Q21@73d65a5

Preparing for the Java 2 Certification exam

Preparing for the Java 2 Certification exam
vipin bhatia
Ranch Hand

Joined: Jul 14, 2001
Posts: 31
You will have to initialize all automatic variables ( method locals). Unlike member variables which the compiler initializes before calling the constructor, the local variables have to be initialized by the programmer.

Sun Certified Programmer for Java2 Platform scored 100%.
Jane Griscti
Ranch Hand

Joined: Aug 30, 2000
Posts: 3141
Local variables must be initialized before they can be used. See JLS §4.5.5
Hope that helps.
Jane Griscti
Sun Certified Programmer for the Java� 2 Platform

Jane Griscti
SCJP, Co-author Mike Meyers' Java 2 Certification Passport
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
subject: default value?