java, extending class with the constructor of main class has parameter

后端 未结 3 1049
粉色の甜心
粉色の甜心 2020-11-29 07:23

hei. the language is java. i want to extend this class which the constructor has parameters.

this is the main class

public class CAnimatedSprite {
           


        
3条回答
  •  一生所求
    2020-11-29 08:09

    The first statement of your constructor must be a call to superclass constructor. The syntax is:

    super(pFn, pWidth, pHeight);
    

    It is up to you to decide, whether you want constructor of your class to have same parameters and just pass them to superclass constructor:

    public CMainCharacter(String pFn, int pWidth, int pHeight) {
        super(pFn, pWidth, pHeight);
    }
    

    or pass something else, like:

    public CMainCharacter() {
        super("", 7, 11);
    }
    

    And don't specify return type for constructors. It's illegal.

提交回复
热议问题