Results 1 to 5 of 5
  1. #1
    JT4NK3D's Avatar
    JT4NK3D is offline Member
    Join Date
    Nov 2007
    Posts
    50
    Rep Power
    0

    Question [SOLVED] Location of Object Declaration

    I'm have a superclass(which is a driver class) that has a method in it which calls a method in the class's subclass. Since this method is the only one that uses this object, should i declare my object in the method? or should i declare it at the start at the program with the fields? Thanks in advance. (p.s. i'm not very good at OOP yet):D
    Last edited by JT4NK3D; 05-29-2008 at 03:01 AM. Reason: clearing it up

  2. #2
    sukatoa's Avatar
    sukatoa is offline Senior Member
    Join Date
    Jan 2008
    Location
    Cebu City, Philippines
    Posts
    556
    Rep Power
    7

    Default

    You may declare it there if that instance should also be used in the next processing....
    freedom exists in the world of ideas

  3. #3
    Eranga's Avatar
    Eranga is offline Moderator
    Join Date
    Jul 2007
    Location
    Colombo, Sri Lanka
    Posts
    11,372
    Blog Entries
    1
    Rep Power
    20

    Default

    If you are use it inside a single method best place is to use it is, on the same method. That's fine. In that case you don't need to hold the memory for that object when it is not used in other methods. And also you can do it in a single line. I really like to use as much as possible, less number of lines.

  4. #4
    JT4NK3D's Avatar
    JT4NK3D is offline Member
    Join Date
    Nov 2007
    Posts
    50
    Rep Power
    0

    Default

    Ok thanks I will declare the object inside the method.
    You just got T4NK3D!
    Adonrcicg to rcesraeh the haumn mnid is clbapae of rdanieg tihs. -Jvaa Sun Moricyssemts-

  5. #5
    Eranga's Avatar
    Eranga is offline Moderator
    Join Date
    Jul 2007
    Location
    Colombo, Sri Lanka
    Posts
    11,372
    Blog Entries
    1
    Rep Power
    20

Similar Threads

  1. Declaration
    By asifahmed in forum New To Java
    Replies: 1
    Last Post: 04-05-2008, 06:38 AM
  2. JSP Declaration Directive
    By Java Tip in forum Java Tip
    Replies: 0
    Last Post: 12-10-2007, 06:42 PM
  3. JFileChooser remember the location
    By Mr tuition in forum AWT / Swing
    Replies: 3
    Last Post: 12-08-2007, 06:17 PM
  4. how to get the location of some button
    By mary in forum Java 2D
    Replies: 2
    Last Post: 08-05-2007, 05:02 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
  •