-1
package InterfaceAbstractOverloadingOverriding;

public class instrumentExecute 
{

    public static void main(String[] args) 
    {
         GuitarAbstract g = new GuitarAbstract();
         NewGuitar ng = new NewGuitar(); 
         g.play();
         ng.play();

         g = new GuitarAbstract(7);
         ng = new NewGuitar(5);
         g.play();
         ng.play();
    }
}

I'm not able to instantiate the GuitarAbstract class

Error:

Cannot instantiate the type GuitarAbstract.GuitarAbstract is an abstract class.
mpromonet
  • 11,326
  • 43
  • 62
  • 91
  • 2
    You can't directly instantiate an abstract class : [http://stackoverflow.com/q/4579305/4682796](http://stackoverflow.com/q/4579305/4682796) – jmgross May 22 '15 at 12:19
  • That's because it's an abstract class. You need to create something concrete that inherits from that class in order to be able to instantiate something. – David Hoelzer May 22 '15 at 13:14
  • Please, follow java naming conventions. Packages are to be all lowercase, classes on the other hand should be camel-case (InstrumentExecute) for example. – zubergu May 24 '15 at 21:44

1 Answers1

2

You can't directly instantiate an abstract class, but you can instantiate an anonymous class for your abstract class.

For example, given the following abstract class:

class GuitarAbstract {

  public abstract void play();
}

You can create an anonymous class like so:

GuitarAbstract guitar = new GuitarAbstract() {

  @Override
  public void play() {
    System.out.println("Playing guitar!");
  }
};