• 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 Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Paul Clapham
  • Tim Cooke
  • Jeanne Boyarsky
  • Liutauras Vilda
Sheriffs:
  • Frank Carver
  • Henry Wong
  • Ron McLeod
Saloon Keepers:
  • Tim Moores
  • Frits Walraven
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
Bartenders:
  • Al Hobbs
  • Piet Souris
  • Himai Minh

Getting it right from the beginning : Object vs Reference

 
Ranch Hand
Posts: 327
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Would someone be willing to tell me if I have forgotten anything in this example code? I'm trying to comment on everything so that I get this right from the get-go.

I really appreciate everyone's help.
Leo
[ edited to reduce the left-right scrolling -ds ]
[ January 31, 2004: Message edited by: Dirk Schreckmann ]
 
Sheriff
Posts: 7023
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Writing similar example programs is exactly what I started doing when I first began learning Java. It's a practice I still hold today, as I learn some knew API or technology.
It looks like you're understanding things.
//Object variables contain a null pointer upon declaration,
//meaning that they don't point to any created object.

Not exactly. Instance member variables, static class member variables, and array members are always automatically initialized upon declaration. Had your example apple variable been simply declared in a method, it would not have been initialized automatically to null as it is when it's an instance member.
If you haven't already stumbled across it, I'd recommend a read of a couple JavaRanch Campfire Stories - "Cup Size" and "Pass-by-Value Please" - just to help clarify the situation.
 
For my next trick, I'll need the help of a tiny ad ...
the value of filler advertising in 2021
https://coderanch.com/t/730886/filler-advertising
reply
    Bookmark Topic Watch Topic
  • New Topic