Forums Register Login

How to cover or invoke anonymous inner class??

+Pie Number of slices to send: Send
Here is my class





How to print the two sentence ??
Please help me
P.S. codes are for learning only
+Pie Number of slices to send: Send
What print functions? You do not have any functions in that code.
To call the methods of Listeners, you would need an event object which they are listening for. Why are you using listener interfaces of your own which the Java platform is not aware of?
For the Runnable, you would have to pass that to the constructor of a Thread and call the start method.
+Pie Number of slices to send: Send
 

Campbell Ritchie wrote:What print functions? You do not have any functions in that code.
To call the methods of Listeners, you would need an event object which they are listening for. Why are you using listener interfaces of your own which the Java platform is not aware of?
For the Runnable, you would have to pass that to the constructor of a Thread and call the start method.




Sorry, I mean the two sentences.

that's an example , the real codes are more or less the same. I just want to know how to print out the sentence enclosed in it.
Then, what do you mean by the start method?? Are you trying to say " test t=new test(); t.go() ; "?(but it doesn't work)
+Pie Number of slices to send: Send
 

chuen abc wrote:
what do you mean by the start method?



Please see the api docs for the Thread class (that implements Runnable).

You could use the constructor:
public Thread(Runnable target)

It has a simple example on it, that leads up to the code:

PrimeRun p = new PrimeRun(143);
new Thread(p).start();

That way you would be able to print the statements in the run method.
+Pie Number of slices to send: Send
 


Please see the api docs for the Thread class (that implements Runnable).

You could use the constructor:
public Thread(Runnable target)

It has a simple example on it, that leads up to the code:

PrimeRun p = new PrimeRun(143);
new Thread(p).start();

That way you would be able to print the statements in the run method.



I am so sorry that I cannot get it.
Dream p = new Dream();
new Thread(p).start();

I try the above codes ,but still cannot print the result.
+Pie Number of slices to send: Send
 

chuen abc wrote:
I am so sorry that I cannot get it.
Dream p = new Dream();
new Thread(p).start();

I try the above codes ,but still cannot print the result.




I was referring you to read up the Java API docs for clearing the concept in discussion as it is a very good starting point and what I noted was an example from there.

For running the code you have pasted, made some minor changes to fix the code:



It gives me the output:


That's Great
Thread-0

+Pie Number of slices to send: Send
Your method is good. But I am not allowed to change the class test, what can I do to invoke it??(Or there should be something in the test, so that I can invoke them )
By the way,do you know how to invoke the gogo class's println.
Whatever you say buddy! And I believe this tiny ad too:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com


reply
reply
This thread has been viewed 1006 times.
Similar Threads
anonymous inner class output
target Runnable of a thread
can anybody tel me wat exactly Thread.start() will do?
Query on threads ?
Thread, Runnable and their run() method
More...

All times above are in ranch (not your local) time.
The current ranch time is
Mar 28, 2024 05:49:36.