Java Forums

Main Menu
Home
Today's Posts
FAQ
Search
Contact Us

Java Network
Java Tips
Java Tips Blog

Sponsored Links





Welcome to the Java Forums.

You are currently viewing our boards as a guest which gives you limited access to view most discussions and access our other features. By joining our free community, you will:

  • have access to post topics
  • communicate privately with other members (PM)
  • not see advertisements between posts
  • have the possibility to earn one of our surprises if you are an active member
  • access many other special features that will be introduced later.

Registration is fast, simple and absolutely free so please, join our community today!

If you have any problems with the registration process or your account login, please contact us.

Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 11-27-2007, 11:12 PM
Member
 
Join Date: Nov 2007
Posts: 20
Gilgamesh is on a distinguished road
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?)

Code:
public main method (){ method2(); method3(); } public void method2(){ blah blah blah} public method3 (){ blah blah blah return value; }
how can we use in a (return) method a variable that is included in a previous (void) method?
Bookmark Post in Technorati
Reply With Quote
Sponsored Links
  #2 (permalink)  
Old 11-27-2007, 11:39 PM
Senior Member
 
Join Date: Jul 2007
Posts: 1,124
hardwired is on a distinguished road
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; } }
Bookmark Post in Technorati
Reply With Quote
  #3 (permalink)  
Old 11-27-2007, 11:54 PM
Member
 
Join Date: Nov 2007
Posts: 20
Gilgamesh is on a distinguished road
you are fast thanx


if i wanted to return the ''somethingElse '' to the method getSomething, i would write this
Code:
String retVal = doSomethingElse(s); System.out.println("retVal = " + retVal);
as it is inside the getSomething method (and no reference of it in the main method)?
Bookmark Post in Technorati
Reply With Quote
  #4 (permalink)  
Old 11-28-2007, 12:18 AM
Senior Member
 
Join Date: Jul 2007
Posts: 1,124
hardwired is on a distinguished road
A method can call other methods.
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"; }
Bookmark Post in Technorati
Reply With Quote
Sponsored Links
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Stuck on Two Questions, Please Help sylo18 New To Java 5 03-11-2008 02:03 AM
2 simple java questions jimJohnson New To Java 2 02-02-2008 10:35 AM
Just a Few Questions pringle New To Java 21 01-09-2008 07:21 PM
few java questions hiaslpix New To Java 4 01-01-2008 06:47 AM
3 Questions hiranya AWT / Swing 4 11-14-2007 05:57 AM


All times are GMT +3. The time now is 09:08 AM.


VBulletin, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO ©2007, Crawlability, Inc.
Copyright ©2006 - 2007, www.java-forums.org