Instance of on-the-fly class

Isn’t there a syntax in Scala for creating an instance of an unnamed class which is a subclass of a named class?

For example, if I have an abstract class named A, and I want to create a single instance (for a test case) of a subclass of A. I.e., I want to provide methods and values for the unimplemented methods of A, and pass an instance of this class to some function. Do I really need to define the class and name it and create a new instance of that class?

How about:

abstract class A {
  def b: String
} 
new A {
  def b = "foo"
}
3 Likes