Results 1 to 3 of 3
- 12-14-2010, 01:02 AM #1
Member
- Join Date
- Dec 2010
- Posts
- 2
- Rep Power
- 0
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.
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.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); } }
Exception in thread "main" java.lang.RuntimeException: Uncompilable source code
at Methods.main(Methods.java:18)
Java Result: 1
- 12-14-2010, 01:23 AM #2
- Join Date
- Jul 2007
- Location
- Colombo, Sri Lanka
- Posts
- 11,374
- Blog Entries
- 1
- Rep Power
- 18
In main method you have not declare the variable calcs. Without declaring you cannot use any.
- 12-14-2010, 01:25 AM #3
- Join Date
- Jul 2007
- Location
- Colombo, Sri Lanka
- Posts
- 11,374
- Blog Entries
- 1
- Rep Power
- 18
Here,
you have create an object to the same class (refereed). What you really going to do that with it?Java Code:Methods calc = new Methods();
Similar Threads
-
accessing variable/methods of a instantiated object
By hariza in forum AWT / SwingReplies: 5Last Post: 10-11-2010, 01:16 AM -
Accessing GUI object methods
By km0r3 in forum AWT / SwingReplies: 5Last Post: 10-06-2010, 01:39 AM -
How can I implement the String's length() method?
By kiregad in forum New To JavaReplies: 6Last Post: 03-26-2010, 06:06 AM -
Error Accessing Methods in My JAR file
By avu in forum Advanced JavaReplies: 4Last Post: 03-23-2010, 12:35 AM -
accessing instance variables from static methods
By ravian in forum New To JavaReplies: 7Last Post: 03-01-2009, 10:09 PM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks