https://stackoverflow.com/questions/4579305/can-we-instantiate-an-abstract-class
You can't directly instantiate an abstract class, but you can create an anonymous class when there is no concrete class:
AsyncTask.java
import java.io.*; public abstract class AsyncTask { protected abstract boolean doInBackground(String params); public void asyncTaskPrint() { System.out.println("AsyncTask"); }; }
Test.java
import java.io.*; public class Test{ public static void main(String [] args){ System.out.println("hello"); AsyncTask asyncTask = new AsyncTask() { public void printSomethingOther() { System.out.println("other"); } @Override protected boolean doInBackground(String params) { System.out.println("world"); printSomethingOther(); return false; } }; asyncTask.doInBackground(""); asyncTask.asyncTaskPrint(); } }