Monday, April 23, 2018

Is there any way to create the instance of an abstract class ?

  1. public class MyMain{
  2. public static void main(String[] args) { // start
  3. MyAbstractClass exe = new MyAbstractClass() {
  4. @Override
  5. void run() {
  6. System.out.println("run of abstract class");
  7. }
  8. };
  9. System.out.println(exe.x);
  10. exe.run();
  11. } // end
  12. }

  13. abstract class MyAbstractClass {
  14. int x = 10;
  15. abstract void run();
  16. }
Output: 
10
run of abstract class

Note: Yes ! using anonymous class we can create the instance of an abstract class.

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...