what is need of declare Listener inside java class ? I have class ClassDemo.java if i declare interface inside class rather that out side of class then what its impact,What are pros and cons of it?
To encapsulate the behaviour in generic and reusable way.So, basically, your interface visibility will be limited. Interface defines the methods but does not implement it. But the class which implements the listener(interface) will implement all the methods of that interface.
Now suppose I want to pass some result from class A to class B. This will become easier if we execute interface kind of methodology. So when the result is calculated by class A, it will update it to interface inside it and now as class B implements the interface , the result will be automatically given to class B.
If you need to pass something to your listener, it's better to create it in another class so you can pass the parameters to the costructor.
Making it on you main class is only more readable and handy if you don't want a lot of classes