public class Child extends Father{
public Child(String a) {
super(a); //这个是怎么回事,我知道是调用父类的a参数的构造函数,但构造函数是什么,
}
}
我在父类中声明的有参构造器是这样的:
public Father(String a){
System.out.println("有参父类构造函数被调用");
}我想问子类的super(a)是不是等同于父类的(string a)含有的方法System.out.println("有参父类构造函数被调用");,子类的输出结果就是:有参父类构造函数被调用 ,是不是,我的理解有没错
public Child(String a) {
super(a); //这个是怎么回事,我知道是调用父类的a参数的构造函数,但构造函数是什么,
}
}
我在父类中声明的有参构造器是这样的:
public Father(String a){
System.out.println("有参父类构造函数被调用");
}我想问子类的super(a)是不是等同于父类的(string a)含有的方法System.out.println("有参父类构造函数被调用");,子类的输出结果就是:有参父类构造函数被调用 ,是不是,我的理解有没错
SensorEventListener {
这是子代码:public MyView(Context context) {
super(context);this.context = context;
其他省略了。为什么要套用父类surfaceview的context参数构造方法,就算套用了,不能直接就一个super(context)就行了么?为什么还要传入Context context这个参数,在用context获取父类的context参数的方法。这myview是我自定义的类
super(context); this.context = context;
/** 设置当前View拥有控制焦点 **/
this.setFocusable(true);
/** 设置当前View拥有触摸事件 **/
this.setFocusableInTouchMode(true);
/** 拿到SurfaceHolder对象 **/
mSurfaceHolder = this.getHolder();
/** 将mSurfaceHolder添加到Callback回调函数中 **/
mSurfaceHolder.addCallback(this);
/** 创建画布 **/
mCanvas = new Canvas();
/** 创建曲线画笔 **/
mPaint = new Paint();
mPaint.setColor(Color.WHITE); /** 加载小球资源 **/
mbitmapBall = BitmapFactory.decodeResource(this.getResources(),
R.drawable.ball);
/** 加载游戏背景 **/
mbitmapBg = BitmapFactory.decodeResource(this.getResources(),
R.drawable.bg); /** 得到SensorManager对象 **/
mSensorMgr = (SensorManager) context.getSystemService(context.SENSOR_SERVICE);
mSensor = mSensorMgr.getDefaultSensor(Sensor.TYPE_ACCELEROMETER);
// 注册listener,第三个参数是检测的精确度
// SENSOR_DELAY_FASTEST 最灵敏 因为太快了没必要使用
// SENSOR_DELAY_GAME 游戏开发中使用
// SENSOR_DELAY_NORMAL 正常速度
// SENSOR_DELAY_UI 最慢的速度
mSensorMgr.registerListener(this, mSensor, SensorManager.SENSOR_DELAY_GAME);
} private void Draw() { /** 绘制游戏背景 **/
mCanvas.drawBitmap(mbitmapBg, 0, 0, mPaint);
/** 绘制小球 **/
mCanvas.drawBitmap(mbitmapBall, mPosX, mPosY, mPaint); /** X轴 Y轴 Z轴的重力值 **/
mCanvas.drawText("X轴重力值 :" + mGX, 0, 20, mPaint);
mCanvas.drawText("Y轴重力值 :" + mGY, 0, 40, mPaint);
mCanvas.drawText("Z轴重力值 :" + mGZ, 0, 60, mPaint);
}
public MyView(Context context) {
super(context);this.context = context;