Win a copy of The Java Performance Companion this week in the Performance forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Doubt with cert objective - accessing object fields

 
Andy James
Ranch Hand
Posts: 90
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 1051
5
Chrome Eclipse IDE Hibernate
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Sheriff
Posts: 10225
129
AngularJS Chrome Eclipse IDE Hibernate Java jQuery MySQL Database Spring Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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:
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic