| | |
Return Boolean to main
Please support our Java advertiser: Programming Forums - DaniWeb Sister Site
Thread Solved |
•
•
Join Date: Mar 2008
Posts: 14
Reputation:
Solved Threads: 0
Hi,
I have a couple of classes and I am trying to do the following:
I have a main class that contains a boolean value called "display" that displays various messages throughout the class depending on true/false values.
Main class example:
Class A example:
public class A{
Now the main class calls another class method, we can call the class A and the method B.
Now from method B i am trying to return a value for the boolean that is declared in main class. However i have tried doing something like:
But that does not work. Does anyone know how i get the main class to recognize the false/true return type from method B and assign it to its own boolean "display" ?
Thanks
I have a couple of classes and I am trying to do the following:
I have a main class that contains a boolean value called "display" that displays various messages throughout the class depending on true/false values.
Main class example:
Java Syntax (Toggle Plain Text)
public static void main (String[] args) { boolean display; switch (input1) { case 'A': System.out.print("please enter value"); inputInfo = stdin.readLine().trim(); A.B(inputInfo); // call method B in class A if (display == true) System.out.print("Not Found"); else System.out.print("Found"); break; }
public class A{
Java Syntax (Toggle Plain Text)
public boolean B(String input) { //not sure how to return a boolean so it is recognized by main class in switch case A }
Now from method B i am trying to return a value for the boolean that is declared in main class. However i have tried doing something like:
Java Syntax (Toggle Plain Text)
return false;
But that does not work. Does anyone know how i get the main class to recognize the false/true return type from method B and assign it to its own boolean "display" ?
Thanks
Java Syntax (Toggle Plain Text)
boolean display = A.B(inputInfo);
The return statement you used is legal. You can return false, true, or a boolean variable when using a boolean method. When you call A.B() that line of code becomes (basically anyways) the data type you are returning. That is why if you have a method that returns a String you can say
Java Syntax (Toggle Plain Text)
String testString = Class.returnMethod(someVariable)
Last edited by jasimp; Mar 16th, 2009 at 11:17 pm.
"Argyou not with the hand you are dealt in cards or life." ---- Wizard and Glass
![]() |
Other Threads in the Java Forum
- Previous Thread: Simple JTable Data Issue
- Next Thread: urgent!! need help!
| Thread Tools | Search this Thread |
-xlint actionlistener android api applet application array arrays automation binary blackberry block bluetooth character chat class classes client code component consumer database desktop developmenthelp draw eclipse error event exception fractal ftp game gameprogramming givemetehcodez graphics gui html ide image input integer j2me j2seprojects java javac javaee javaprojects jmf jni jpanel julia lego linked linux list loop loops mac map method methods mobile netbeans newbie notdisplaying number online oracle print printf problem program programming project properties recursion researchinmotion rotatetext rsa scanner screen server set singleton size sms sort sql string swing template textfields threads time title tree tutorial-sample update windows working






