There are classes and there is anonymous class?
Guys,
Please help me out again. I just put a programme skeleton below:
public class ThatClass
{
public ThatClass( )
{
// Initialization codes
}
}
// ****************************************************************************
public class ThisClass
{
public ThisClass( )
{
return new ThisClass( );
{
public ThatClass makeObject( )
{
return new ThatClass( );
}
public ThatClass createInstance( )
{
return new ThatClass( )
{
// codes that define anonymous class
};
}
}
//*****************************************************************************
Note: ThisClass and ThatClass are in the same package.
I am aware that the statement "return new ThatClass( ); " returns an object of ThatClass.
What does the statement "return new ThatClass( ) { // codes for anonymous class}; " return - an object of ThatClass or an object of the anonymous class?
Thanks.
ue_Joe
[1083 byte] By [
ue_Joea] at [2007-11-27 10:51:58]

Thanks everybody. The picture is getting clearer. But if the instance returned is an anonymous extension of ThatClass, how can I use this instance - assign it to a reference such as:
ThatClass myStuff = new (getThatClass( )); ?
ue_Joe.
It seems you are coonfused as to the meaning of anonymous class.
button.addActionListener( new ActionListener() {
public void actionPerformed(ActionEvent e) {
// do stuff
}
});
In the above example the ActionListener is an anonymous class.
MyObject o = new MyObject();
The reserved word new is an operator. When it executes it will call the constructor of the class that follows it. An object is then created by executing the code inside the constructor (and all super constructors). Once the object has been created it is placed on the heap and a reference to that object is stored in the variable. The following link may help.
http://java.sun.com/docs/books/tutorial/java/javaOO/objectcreation.html
Thanks. So then what is the diference between
myObject o = new myOjbect( ) {// codes} and
myObject o = new myOjbect( ) {codes} ; ?
This is the genesis of all these tortuous questions tonight.
ue_Joe.