Results 1 to 4 of 4
  1. #1
    rangers27 is offline Member
    Join Date
    Jul 2008
    Posts
    3
    Rep Power
    0

    Default executing a method in main class

    Hello I need help. I'm learning Java and have been stuck on this for the past few days (I hope I will laugh at this one day!)


    the problem I'm having is executing a method belonging to a class within the same package inside the main class's main method. Can you please make some suggestions.

    Thank you
    Last edited by rangers27; 07-19-2008 at 05:40 AM.

  2. #2
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    SW Missouri
    Posts
    17,259
    Rep Power
    25

    Default

    If you are getting compiler error message, please copy and paste them here.

    Which Owner class method are you trying to execute?
    You've defined the Owner class as a "singleton". Is that part of the assignment?

    To get a reference to the Owner class you'd use the static method in Owner that returns a reference to it:
    Owner ownr = Owner.getInstance(); // get reference to Owner

    Then to call a method would be like with any other class:
    ownr.<methodname>[(<args>)];

  3. #3
    rangers27 is offline Member
    Join Date
    Jul 2008
    Posts
    3
    Rep Power
    0

    Default

    Norm thank you for your reply. Yes the Singleton is part of the intent. The method I'm trying to execute is getOwner so it would return the string "what can I do for you".

    The error I keep getting is type Owner cannot be resolved. I tried to cast Owner but the error continues.

    Once again thank you for your help.

  4. #4
    rangers27 is offline Member
    Join Date
    Jul 2008
    Posts
    3
    Rep Power
    0

    Default thank you

    Norm thank you. I took out the cast and did what you advised and it worked? Thank you for your help

Similar Threads

  1. Calling main method
    By eva in forum New To Java
    Replies: 7
    Last Post: 11-06-2009, 01:37 PM
  2. How to create main class link to another two class?
    By pearllymary78 in forum New To Java
    Replies: 6
    Last Post: 07-16-2008, 11:02 PM
  3. A query about main method
    By mew in forum New To Java
    Replies: 2
    Last Post: 12-24-2007, 09:44 AM
  4. Private main method
    By bugger in forum New To Java
    Replies: 1
    Last Post: 12-21-2007, 09:45 AM
  5. main method
    By eva in forum New To Java
    Replies: 5
    Last Post: 12-19-2007, 09:25 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
  •