Results 1 to 4 of 4
Thread: questions
- 11-27-2007, 10:12 PM #1
Member
- Join Date
- Nov 2007
- Posts
- 20
- Rep Power
- 0
questions
when we are creating a new class, and we want to make use of a lot of methods, we do something like this? (we put all the methods inside the main method? or only the void methods?)
how can we use in a (return) method a variable that is included in a previous (void) method?Java Code:public main method (){ method2(); method3(); } public void method2(){ blah blah blah} public method3 (){ blah blah blah return value; }
- 11-27-2007, 10:39 PM #2
Java Code:public class MethodsTest { public static void main(String[] args) { doSomething(); String s = getSomething(); String retVal = doSomethingElse(s); System.out.println("retVal = " + retVal); } private static void doSomething() { System.out.println("doingSomething"); } private static String getSomething() { return "something"; } private static String doSomethingElse(String s) { return "somethingElse " + s; } }
- 11-27-2007, 10:54 PM #3
Member
- Join Date
- Nov 2007
- Posts
- 20
- Rep Power
- 0
you are fast thanx
if i wanted to return the ''somethingElse '' to the method getSomething, i would write thisas it is inside the getSomething method (and no reference of it in the main method)?Java Code:String retVal = doSomethingElse(s); System.out.println("retVal = " + retVal);
- 11-27-2007, 11:18 PM #4
A method can call other methods.
Java Code:public static void main(String[] args) { String s = getSomething(); System.out.println("s = " + s); } private static String getSomething() { String s = getSomethingElse(); return "something + " + s; } private static String getSomethingElse() { return "somethingElse"; }
Similar Threads
-
Stuck on Two Questions, Please Help
By sylo18 in forum New To JavaReplies: 5Last Post: 03-11-2008, 01:03 AM -
2 simple java questions
By jimJohnson in forum New To JavaReplies: 2Last Post: 02-02-2008, 09:35 AM -
Just a Few Questions
By pringle in forum New To JavaReplies: 21Last Post: 01-09-2008, 06:21 PM -
few java questions
By hiaslpix in forum New To JavaReplies: 4Last Post: 01-01-2008, 05:47 AM -
3 Questions
By hiranya in forum AWT / SwingReplies: 4Last Post: 11-14-2007, 04:57 AM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks