Search code examples
javainterfaceabstract-class

How to create abstract class object which implements interface ( JAVA )


I have an interface

public interface I{
  Status getStatus();
}

then I have an abstract class implementing that interface

public abstract class C implements I{
       public Status getStatus() {
        return status;
    }
}

I want to access the getstatus() method from another class, I have tried

C status = new C();

but I am getting error "Cannot instantiate the type C"

Any help will be highly appreciated..!! thanx.


Solution

  • You can not create object for an abstract class Write a concrete class which extends your abstract class and use that class object to call the method

     class test extends c{
          ..........
         }
    
        c  obj1= new test();
       obj1.getStatus();