• 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
  • Devaka Cooray
  • Knute Snortum
  • Paul Clapham
  • Tim Cooke
Sheriffs:
  • Liutauras Vilda
  • Jeanne Boyarsky
  • Bear Bibeault
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Ron McLeod
  • Piet Souris
  • Frits Walraven
Bartenders:
  • Ganesh Patekar
  • Tim Holloway
  • salvin francis

default value?  RSS feed

 
Ranch Hand
Posts: 37
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Can a local uninitialized(only declared) object get the default value?
Thanks.
 
Ranch Hand
Posts: 55
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
Ranch Hand
Posts: 31
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Ranch Hand
Posts: 3141
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
I'm not sure if I approve of this interruption. But this tiny ad checks out:
ScroogeXHTML - small and flexible RTF to HTML converter library
https://coderanch.com/t/710903/ScroogeXHTML-RTF-HTML-XHTML-converter
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!