Don't worry, you will have to do a bit of correction
Both are ways to access the private member of a class. By using first way you don' have to pre-declare the method.ex: -
public class demo {
public static void main(String[] args) {
new Object() {
public void a() {
/*code*/
System.out.println("Hello");
}
}.a();
}
}
But by using second way you will have to explicitly declare the method a(); either in abstract class or in interface then you can override it. like: -
interface Object
{
public void a();
}
class demo {
public static void main(String[] args) {
Object object = new Object() {
public void a() {
System.out.println("Hello");
}
}; object.a();
}
}
I hope it will help a bit.