- public class MyMain{
- public static void main(String[] args) { // start
- MyAbstractClass exe = new MyAbstractClass() {
- @Override
- void run() {
- System.out.println("run of abstract class");
- }
- };
- System.out.println(exe.x);
- exe.run();
- } // end
- }
- abstract class MyAbstractClass {
- int x = 10;
- abstract void run();
- }
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