Missing Method body, or declare abstract

后端 未结 2 1328
梦如初夏
梦如初夏 2021-01-28 04:55

I am getting this error message:

Exception in thread \"main\" java.lang.RuntimeException: Uncompilable source code - Erroneous sym type: Pet.saySomething

相关标签:
2条回答
  • 2021-01-28 05:43

    You have the following options for Speak, take your pick:

    1st

    public abstract class Speak{
    
       public abstract void saySomething();
    
    }
    

    2nd

    public class Speak{
    
       public void saySomething(){
    
       }
    }
    

    3rd

    public interface Speak{
    
       public void saySomething();
    }
    

    Edit: First of all, you are not using Speak class anywhere. Second, please add the following method in Pet class:

     public abstract void saySomething();
    
    0 讨论(0)
  • 2021-01-28 05:44

    If Speak is a concrete class, it must implement all of its methods, so saySomething must have a body.

    However, it looks like Speak is more suitable to be an interface. Your Pet class can implement that interface.

    0 讨论(0)
提交回复
热议问题