This week's book giveaway is in the OO, Patterns, UML and Refactoring forum.
We're giving away four copies of Refactoring for Software Design Smells: Managing Technical Debt and have Girish Suryanarayana, Ganesh Samarthyam & Tushar Sharma on-line!
See this thread for details.
The moose likes Junior/Associate Certification (SCJA,OCAJ 5/6/8) 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

JavaRanch » Java Forums » Certification » Junior/Associate Certification (SCJA,OCAJ 5/6/8)
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: 1051

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: 7216

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:
subject: Doubt with cert objective - accessing object fields
It's not a secret anymore!