Results 1 to 3 of 3
  1. #1
    carderne is offline Senior Member
    Join Date
    Nov 2007
    Posts
    160
    Rep Power
    7

    Default Method access or field access

    If I want to access a field in an object from another class, is it better to access the field directly, i.e. Object.field or should you rather do it with a method, i.e. Object.getField()

    Which, by convention, is thought of as better?

  2. #2
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    25

    Default

    It's better to use accessors and mutators as you'll have more control over access to the field.

  3. #3
    carderne is offline Senior Member
    Join Date
    Nov 2007
    Posts
    160
    Rep Power
    7

    Default

    Okay. And accessing a static field?

    Another question: I have a class with an instance field and a static field. Is there any way that I can make an object of the class where any reference to the instance field automatically accesses the static field? Like a shortcut...

Similar Threads

  1. remote access
    By Omarero in forum NetBeans
    Replies: 1
    Last Post: 11-03-2008, 07:36 AM
  2. MS Access with Java
    By Doctor Cactus in forum New To Java
    Replies: 4
    Last Post: 10-24-2008, 02:59 AM
  3. Access with MS SQL
    By cachi in forum JDBC
    Replies: 1
    Last Post: 08-07-2007, 07:54 AM
  4. Replies: 1
    Last Post: 08-07-2007, 07:51 AM
  5. access cd drive
    By milinkp in forum New To Java
    Replies: 0
    Last Post: 07-20-2007, 06:14 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •