Consider the following piece of code (code 2).
abstract class Vehicle{
abstract void park();
}
class Demo{
static class Car extends Vehicle {
int speed;
void park(){
System.out.println("Parking for cars...");
}
}
public static void main(String args[]){
Vehicle v1=new Car();
v1.park();
}
}
It is no surprise that the previous piece of code gives no compiler error.
Car extends Vehicle and Car is not abstract. Hence you can instantiate it.
Lets see what happens when code 2 is compiled :
javac *.java
list .class files
Demo$Car.class Demo.class Vehicle.class
And this is what happens when the code in the question (code 1) is compiled :
javac *.java
list .class files
Demo$1.class Demo.class Vehicle.class
We get the same except we get Demo$1.class in code 1 and Demo$Car.class in code 2.
That happens because code 1 is actually creating a class which inherits from Vehicle. A so called anonymous class. The class has no name(*) but it is still a full fledged class which inherits from Vehicle and can be instantiated just as Car can be instantiated.
This code :
Vehicle v1=new Vehicle(){
is NOT instantiating an object of class Vehicle. It is instantiating an object of a class which inherits from Vehicle which has no name.
(*) Actually it does have a name. Its name is "1 in Demo" aka Demo$1. The JVM needs a name to be able to run it, you can't just tell the JVM to run something without telling it what to run. The name is one which is not a sintactically valid name for a class; can't name a class as 1. This is by dessign as it ensures that annonymous class names won't clash with normal class names.