嘿嘿.语言是java.我想扩展构造函数具有参数的类.
这是主要的课程
public class CAnimatedSprite {
public CAnimatedSprite(String pFn, int pWidth, int pHeight) {
}
}
Run Code Online (Sandbox Code Playgroud)
这是儿童班
public class CMainCharacter extends CAnimatedSprite {
//public void CMainCharacter:CAnimatedSprite(String pFn, int pWidth, int pHeight) {
//}
}
Run Code Online (Sandbox Code Playgroud)
我该如何编写正确的语法?并且错误是"构造函数不能应用于给定类型"
Tho*_*zer 41
您可以为构造函数定义所需的任何参数,但是必须将超类的一个构造函数作为您自己的构造函数的第一行.这可以使用super()或完成super(arguments).
public class CMainCharacter extends CAnimatedSprite {
public CMainCharacter() {
super("your pFn value here", 0, 0);
//do whatever you want to do in your constructor here
}
public CMainCharacter(String pFn, int pWidth, int pHeight) {
super(pFn, pWidth, pHeight);
//do whatever you want to do in your constructor here
}
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
82507 次 |
| 最近记录: |