File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
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
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: 973
    
    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: 4910
    
  10

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
Difference of this.xxx and xxx
classes, help
what is Field Access vs. Property Access in JPA ? please give example in detail
java.lang.Reflection throwing error when using (String)field.get(new String());
Accessing Outer Class