A man of words and not of deeds is like a garden full of weeds, and when the weeds begin to grow, its like a garden full of snow, and when the snow begins to fall- its like a bird upon the wall and when the bird begins to fly, its like an eagle in the sky
<a href="http://faq.javaranch.com/java/UseCodeTags" target="_blank">Use Code Tags!!</a>
Mary Dawson wrote:
I have to get the run method to return the getName() method's output- but using a return statement seems to contradict the requirements of the run() method - which is to return a void type.
<a href="http://faq.javaranch.com/java/UseCodeTags" target="_blank">Use Code Tags!!</a>
A man of words and not of deeds is like a garden full of weeds, and when the weeds begin to grow, its like a garden full of snow, and when the snow begins to fall- its like a bird upon the wall and when the bird begins to fly, its like an eagle in the sky
Upon posting this,I have noticed several more replies, the gist of which suggest that a run method can't return anything but a void and as such its signature must be thus writ. My teacher considers that it can invoke a method to return that value - ie using System.out.println(getName()) in the run method, but the console doesn't agree - and has the last word.
Mary Dawson wrote:
Dear Henry Wong:
If I code the program this way:-
[EXAMPLE DELETED for brevity -- but see post above]
If I change the very last line of program OneThread to :-
[EXAMPLE DELETED -- again, see post above]
I get the same response.
If I change the last line to:-
[EXAMPLE DELETED -- again, see post above]
I get :-
[EXAMPLE DELETED -- again, see post above]
ie: you get stuck in a no-win situation: Without a return statement in the run() method -
you get a console request for a return statement, if a return statement is put in - then
you are requesting a necessarily void run method return a value which must be of some data
type - which again console will reject.
the gist of which suggest that a run method can't return anything but a void and as such its signature must be thus writ. My teacher considers that it can invoke a method to return that value
ie using System.out.println(getName()) in the run method,
A man of words and not of deeds is like a garden full of weeds, and when the weeds begin to grow, its like a garden full of snow, and when the snow begins to fall- its like a bird upon the wall and when the bird begins to fly, its like an eagle in the sky
A man of words and not of deeds is like a garden full of weeds, and when the weeds begin to grow, its like a garden full of snow, and when the snow begins to fall- its like a bird upon the wall and when the bird begins to fly, its like an eagle in the sky
SCJP 1.4 - SCJP 6 - SCWCD 5 - OCEEJBD 6 - OCEJPAD 6
How To Ask Questions How To Answer Questions
Does this mean that I cannot therefore use methods setName() & getName()
in a class that is subclassed of Thread, and am therefore best off using call().
and forgetting about using them in my program OneThread, or TwoThread - can
someone tell me, so's I (we) can stop spending any more time on this conundrum.
Thank you for your previous advice, and for any forthcoming advice (if you
still feel like talking to me, that is).
Steve
A man of words and not of deeds is like a garden full of weeds, and when the weeds begin to grow, its like a garden full of snow, and when the snow begins to fall- its like a bird upon the wall and when the bird begins to fly, its like an eagle in the sky
Mary Dawson wrote:
I have done ‘overidding’ previously, but it seems its one thing to do something in a lesson, but another to actually apply it.
Thank you for your help.
TwoThread.java:11: getName() in TwoThread cannot override getName() in java.lang.Thread; overridden method is final
Steve
Rob Prime wrote:Mary, the end tag of a code block only has one /: [/code]
SCJP 1.4 - SCJP 6 - SCWCD 5 - OCEEJBD 6 - OCEJPAD 6
How To Ask Questions How To Answer Questions
