This week's giveaway is in the Android forum.
We're giving away four copies of Android Security Essentials Live Lessons and have Godfrey Nolan on-line!
See this thread for details.
The moose likes Associate Certification (SCJA,OCAJ 5/6) and the fly likes Doubt with cert objective - accessing object fields 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 » Associate Certification (SCJA,OCAJ 5/6)
Bookmark "Doubt with cert objective - accessing object fields" Watch "Doubt with cert objective - accessing object fields" New topic
Author

Doubt with cert objective - accessing object fields

Andy James
Ranch Hand

Joined: Aug 22, 2005
Posts: 90
Hey Ranchers,

Are the object fields same as instance variables?

For example, in the following class, which is an object field - name or myName?



Are the field names derived from the exact names of the instance variable or from the method names?

Cheers
Andy
James Boswell
Bartender

Joined: Nov 09, 2011
Posts: 1012
    
    5

myName is an instance variable here. Nothing is derived although modern IDEs can generate setter and getter methods based upon the names of instance variables.
Roel De Nijs
Bartender

Joined: Jul 19, 2004
Posts: 5147
    
  12

That's a class that won't compile, because name is not an existing parameter.

myName is the instance variable (or object field as you like)
value is the parameter

In real world, you have something like this:


And then as James already mentioned you let your IDE generate the necessary getters and setters (it's a lot faster than typing them yourself). So you'll end up with this class:


SCJA, SCJP (1.4 | 5.0 | 6.0), SCJD
http://www.javaroe.be/
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Doubt with cert objective - accessing object fields
 
Similar Threads
Accessing Outer Class
Difference of this.xxx and xxx
what is Field Access vs. Property Access in JPA ? please give example in detail
classes, help
java.lang.Reflection throwing error when using (String)field.get(new String());