aspose file tools*
The moose likes Beginning Java and the fly likes How to cover or invoke anonymous inner class?? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Soft Skills this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "How to cover or invoke anonymous inner class??" Watch "How to cover or invoke anonymous inner class??" New topic
Author

How to cover or invoke anonymous inner class??

Qiang Qiang Xi
Greenhorn

Joined: Feb 24, 2013
Posts: 12
Here is my class





How to print the two sentence ??
Please help me
P.S. codes are for learning only
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 40034
    
  28
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.
Qiang Qiang Xi
Greenhorn

Joined: Feb 24, 2013
Posts: 12
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)
Rommel Sharma
Greenhorn

Joined: Oct 31, 2003
Posts: 18
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.
Qiang Qiang Xi
Greenhorn

Joined: Feb 24, 2013
Posts: 12

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.
Rommel Sharma
Greenhorn

Joined: Oct 31, 2003
Posts: 18
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

Qiang Qiang Xi
Greenhorn

Joined: Feb 24, 2013
Posts: 12
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.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: How to cover or invoke anonymous inner class??