jQuery in Action, 3rd edition
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
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
I agree. Here's the link: http://aspose.com/file-tools
subject: default value?
jQuery in Action, 3rd edition