aspose file tools*
The moose likes Beginning Java and the fly likes Anonymous Issue Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of The Java EE 7 Tutorial Volume 1 or Volume 2 this week in the Java EE forum
or jQuery UI in Action in the JavaScript forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Anonymous Issue " Watch "Anonymous Issue " New topic
Author

Anonymous Issue

Mark Henryson
Ranch Hand

Joined: Jul 11, 2005
Posts: 200
Hi,

I heard that inheritance concepts can be achieved by anonymous class(without using extends and implements keyword). Anonymous class will not have the class name. How could we inherit some of the methods or variables of the anonymous class from the other class.
Norm Radder
Ranch Hand

Joined: Aug 10, 2005
Posts: 685
Not sure what you are asking.
Here's a simple anonymous class(off the top so many have syntax errors):


The paint() method can reference variables in the outer class with the proper coding.
I don't know how the outer class can reference variables in the inner class such as the x above??
Steve Morrow
Ranch Hand

Joined: May 22, 2003
Posts: 657

How could we inherit some of the methods or variables of the anonymous class from the other class.

Methods, etc. are inherited the same way as with non-anonymous classes. Ex:
Mark Henryson
Ranch Hand

Joined: Jul 11, 2005
Posts: 200
Hi,
Thanks for the reply. However, It seems to be confusing. Do you know any online tutorials for anonymous class for beginners other than Sun's tutorial.

I am having doubt on ur pgm:


Usually, in thread, we will create the thread object and by calling the start(), the run method will invoke automatically. And also we have to implement the Runnable interface or extends the Thread class for Thread.
The code I can't understand were marked in Bold. If u don't mind can u pls explain me clearly, as if i were a beginner.
Ernest Friedman-Hill
author and iconoclast
Marshal

Joined: Jul 08, 2003
Posts: 24183
    
  34

The code



defines an anonymous class that implements the Runnable interface and creates an instance of it. It's vaguely equivalent to



So that when you put this code into the code you show above, it's similar to

new Thread(new MyRunnable()).start();

which itself is shorthand for

Runnable r = new MyRunnable();
Thread t1 = new Thread(r);
t1.start();

Does this make more sense now?


[Jess in Action][AskingGoodQuestions]
Mark Henryson
Ranch Hand

Joined: Jul 11, 2005
Posts: 200
Thanks a lot. Now it is very much clear!!!
 
jQuery in Action, 2nd edition
 
subject: Anonymous Issue