Results 1 to 3 of 3
  1. #1
    Cyloc is offline Member
    Join Date
    Dec 2010
    Posts
    2
    Rep Power
    0

    Default Accessing int's, String's by methods.

    Hey, I'm having a newbie problem with accessing specific integers (let's take that for instance) in void methods.

    Java Code:
    public class Methods
    {
        public void setVars()
        {
            int num1 = 4;
            int num2 = 12 * 5 / 3;
    
        }
    
        public void calcVars(int num1, int num2, int calcs)
        {
           Methods calc = new Methods();
           calcs = num1 + num2;
        }
    
        public static void main(String args[])
        {
            
            System.out.println(calcs);
        }
    
    }
    The variable calcs should only calculate what is being given by num1 and num2. I forgot how to access that, if that's the error o.o.

    Exception in thread "main" java.lang.RuntimeException: Uncompilable source code
    at Methods.main(Methods.java:18)
    Java Result: 1

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

  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

    Here,

    Java Code:
    Methods calc = new Methods();
    you have create an object to the same class (refereed). What you really going to do that with it?

Similar Threads

  1. Replies: 5
    Last Post: 10-11-2010, 01:16 AM
  2. Accessing GUI object methods
    By km0r3 in forum AWT / Swing
    Replies: 5
    Last Post: 10-06-2010, 01:39 AM
  3. How can I implement the String's length() method?
    By kiregad in forum New To Java
    Replies: 6
    Last Post: 03-26-2010, 06:06 AM
  4. Error Accessing Methods in My JAR file
    By avu in forum Advanced Java
    Replies: 4
    Last Post: 03-23-2010, 12:35 AM
  5. accessing instance variables from static methods
    By ravian in forum New To Java
    Replies: 7
    Last Post: 03-01-2009, 10:09 PM

Posting Permissions

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