Quote:
Originally Posted by mvsprakash
Can we define a class inside a method in JAVA.
If so can u show the code samples, for better understanding
Prakash
|
This is a Java not javascript question so, it probably belongs down in the 'coding forum'.
Yes, however, it would be an anonymous inner class. Generally, to be avoided but, there are cases to use it.
For example, here is a trivial case (though bad example) to start a new thread to run a task asynchronously.
Code:
public void foo(){
// do stuff
Thread thread = new Thread(new Runnable(){
public void run() {
// do some long running task asynchronously
}});
thread.start();
// do other stuff
}
|