Monday, April 23, 2018

Can we create an instance of an interface ?

  1. interface MyInterfaceExe {
  2. MyInterfaceExe exe = new MyInterfaceExe();
  3. }
No ! we cannot instantiate an interface. Compiler will give an error saying that cannot instantiate the type of  MyInterfaceExe.
  1. interface MyInterfaceExe {
  2. MyInterfaceExe exe = new MyInterfaceExe(){ };
  3. }
Yes ! we can create the object of an interface using anonymous class as above.

No comments:

Post a Comment

How to run standalone mock server on local laptop

 Please download the standalone wiremock server from Direct download section at the bottom of the page.  Download and installation Feel fre...