In below chunk of code, I am creating an anonymous class
by extending LinkedList
but don't know how can I call-up multiple methods outside the anonymous class
. I am able to call one method though as mentioned in end by .dummy1()
void methodOC_3() {
int x = 0;
new LinkedList() {
/**
*
*/
private static final long serialVersionUID = -2091001803840835817L;
// Anonymous class is extending class LinkedList
public void dummy1() {
//x=4; Will give error, Or declare x as final variable
//you can read it As Of Now, since it is effectively final.
System.out.println(x);
}
@SuppressWarnings("unused")
public void dummy2() {
dummy1();
System.out.println("Hey there :) ");
}
}.dummy1();
}
I have just started exploring anonymous classes and inner classes. Please let me know if I am missing anything.