How to get a return type?

T

Tom

Hi,

I have a question. I have two methods below.

public void A() {
//some code

return;
}

public boolean B() {

//I want to call A(), but how can I return something like true, or false

}
 
E

Eric Sosman

Tom wrote On 05/30/06 12:04,:
Hi,

I have a question. I have two methods below.

public void A() {
//some code

return;
}

public boolean B() {

//I want to call A(), but how can I return something like true, or false

}

Simplicity itself:

public boolean B() {
A(); // calls A()
return true; // returns "something like" true or false
}

If you don't find this answer satisfactory, please explain
your goals in more detail. For example, describing why this
answer doesn't meet your needs might be a good start.
 
C

Chris Smith

Tom said:
I have a question. I have two methods below.

public void A() {
//some code

return;
}

public boolean B() {

//I want to call A(), but how can I return something like true, or false

}

I'm not sure what you're asking. A() can not return anything, since
it's declared void. B() can return something. If you want B to call A
and then return something, it looks like this:

public boolean B()
{
A();
return true;
}

Incidentally, it would be better to name those methods a and b, not A
and B. Method names in Java begin with lower-case letters.

--
www.designacourse.com
The Easiest Way To Train Anyone... Anywhere.

Chris Smith - Lead Software Developer/Technical Trainer
MindIQ Corporation
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,778
Messages
2,569,605
Members
45,237
Latest member
AvivMNS

Latest Threads

Top