File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/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 Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Certification » Mock Exam Errata
Bookmark "default value?" Watch "default value?" New topic
Author

default value?

jordan gong
Ranch Hand

Joined: Jun 12, 2001
Posts: 37
Can a local uninitialized(only declared) object get the default value?
Thanks.
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();
anotherQ21.aMethod();
}
}

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
Hi,
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
 
wood burning stoves
 
subject: default value?
 
Similar Threads
Data mapping problems ?
default for body-content
Whats the default value of rtexprvalue
no body-cnotent in a tag
Do cast from int to short