• 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
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

understanding an object...

 
Ranch Hand
Posts: 74
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I am looking at an example in my study book and here's the code I want to make sure I fully understand..

Employee adminAssistant = new Employee();

is the First Employee an Object? and is the variable adminAssistant being assigned a new Object, or what?..
 
Ranch Hand
Posts: 109
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Here the first Employee specifies which type the reference variable is (adminEmployee). When you are using new operator as in " new Employee()" this is creating an object of type employee and then a reference to this object is created and assigned to the variable adminEmployee.
 
Ranch Hand
Posts: 241
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Well said Chetan.

To make things clear for a beginner, here is the analysis

Employee adminAssistant = new Employee();

Understanding Step 1 - new Employee();
Hey Java Create me a new Object somewhere on the Heap. Java please note that the object belongs to the class "Employee"

Understanding Step 2- Employee adminAssistant
I want to use a variable "adminAssistant" which gives me an access point to an object of type "Employee" stored somewhere which Im not really aware of

Understanding Step 3- Employee adminAssistant = new Employee();
Java , now I have the variable "adminAssistant" and the object . So I very well know which object the variable "adminAssistant" must refer to. So please use "adminAssistant" as a reference for the object you have created just now with "new Employee();"
[ August 28, 2006: Message edited by: Srikanth Basavaraju ]
 
Jeremy Parsons
Ranch Hand
Posts: 74
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
oh ok, thanks guys that really cleared that up for me...
 
reply
    Bookmark Topic Watch Topic
  • New Topic