What is Anonymous Inner Classes?
As the name suggests , word anonymous means not identified with
name. So, there is no name of the anonymous inner classes , and their type must
be either a subclass of the named type or an implementer of the named
interface.
Example of Anonymous class below :
class Apple {
public
void iphone() {
System.out.println("iphone");
}
}
class Mobile {
Apple
apple = new Apple() {
public
void iphone() {
System.out.println("anonymous iphone");
}
};
An anonymous inner class is always treated like a
statement in the class code , and remember to close the statement after the
class definition with a curly brace. It is rare to found the curly braced
followed by semi colon in java .
When finally block is NOT called?
Finally is the block of code that executes always.
The code in finally block will execute even if an exception is occurred.
Finally block is NOT called in following conditions
If the JVM exits while the try or catch code is
being executed, then the finally block may not execute. This may happen due to
System.exit() call.
if the thread executing the try or catch code is
interrupted or killed, the finally block may not execute even though the
application as a whole continues.
If a exception is thrown in finally block and not
handled then remaining code in finally block may not be executed.
Visit:www.sssedu.inhttp://sssedu.in/java-training-in-chennai.html
No comments:
Post a Comment