How to call abstract class method in java

后端 未结 3 1199
暖寄归人
暖寄归人 2021-01-12 11:14

I want to call a method of an abstract class in my own class. The abstract class is:

public abstract class Call {

    public Connection getEarliestConnectio         


        
3条回答
  •  暖寄归人
    2021-01-12 11:44

    Firstly, Call an abstract class, therefore you cannot instantiate it directly. You must create a subclass, say MyCall extends Call which overrides any abstract methods in Call.

    Getting a NullPointerException means that whatever you are passing in as an argument to getCallFailedString() hasn't been initialized. So after you create your subclass of Call, you'd have to instantiate it and then pass this in to your method, so something like:

    class MyCall extends Call 
    { 
         //override any abstract methods here... 
    }
    

    Wherever you are calling getCallFailedString() would then require something above it like:

    Call cal = new MyCall();
    Activity activity = new MyActivity();
    activity.getCallFailedString(cal);
    

提交回复
热议问题