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 Murach's Java Servlets and JSP this week in the Servlets 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

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?

James Boswell

Joined: Nov 09, 2011
Posts: 1012

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

Joined: Jul 19, 2004
Posts: 5126

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
I agree. Here's the link: http://aspose.com/file-tools
subject: Doubt with cert objective - accessing object fields
Similar Threads
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());
Accessing Outer Class