wood burning stoves 2.0*
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes A question about anonymous inner class. Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "A question about anonymous inner class." Watch "A question about anonymous inner class." New topic
Author

A question about anonymous inner class.

Ling Mike
Greenhorn

Joined: May 17, 2006
Posts: 9
----------------------------
public class Outer{

abstract class Food{
abstract void taste();
}

public static void main(String[] args){
Outer.Food eat = new Outer().new Food(){
public void taste(){
System.out.println("Very delicious.");
}
};
eat.taste();
}

}
---------
OK. It's good compiling and running, but if changing the class Food to an interface as following:
---------
public class Outer{

interface eatable{
void taste();
}

public static void main(String[] args){
Outer.eatable eat = new Outer().new eatable(){
public void taste(){
System.out.println("Very delicious.");
}
};
eat.taste();
}

}
-------
Now, this can not be compiled.
Who can tell me why?
Thanks very much!

BTW: I install the JDK5.0 in Japanese OS, so when I compile or run the java program, the error/warning messages is Japanese. How can I change the messages to English?
Thanks very much.
wise owen
Ranch Hand

Joined: Feb 02, 2006
Posts: 2023

public class Outer{

interface eatable{
void taste();
}

public static void main(String[] args){
Outer.eatable eat = new eatable(){
public void taste(){
System.out.println("Very delicious.");
}
};
eat.taste();
}

}
Henry Wong
author
Sheriff

Joined: Sep 28, 2004
Posts: 18760
    
  40

If I remember correctly, "inner interfaces" are static -- which means that it is closer to an abstract nested class, than an abstract inner class. This also means the correct syntax for declaring one should be...



Henry


Books: Java Threads, 3rd Edition, Jini in a Nutshell, and Java Gems (contributor)
Ling Mike
Greenhorn

Joined: May 17, 2006
Posts: 9
Thank you very much.
The "inner interface" as if is really static.

Now who can help me and answer my second question: How could I change the error/warning messages into English?
Thanks!
 
 
subject: A question about anonymous inner class.