@Hubertoo
2017-07-17T05:26:39.000000Z
字数 2928
阅读 878
达内
class foo{public void f(){sysout("haha");}}class hoo extends foo{public void f(){sysout("hehe");}}//输出结果是heheclass foo{public void f(){sysout("haha");}}class hoo extends foo{public void f(){super.f();sysout("hehe");}}//输出结果是haha hehe
package day02;public class Tetromino {Cell[] cells;public Tetromino(){cells = new Cell[4];}//打印格子中四个格子所在的坐标public void printTetromino(){String str = "";for(int i=0; i<cells.length-1; i++){str += "(" + cells[i].getCellInfo() + "),";}str +="(" +cells[cells.length-1].getCellInfo() + ")";System.out.println(str);}//方块的下落一个格子public void drop(){for(int i=0; i<cells.length;i++){cells[i].row++;}}//方块左移一个格子public void moveLeft(){for(int i=0; i<cells.length;i++){cells[i].col--;}}//方块右移一个格子public void moveRight(){for(int i=0; i<cells.length;i++){cells[i].col++;}}}---package day02;public class TetrominoJ extends Tetromino{public TetrominoJ(int row, int col){super();cells[0] = new Cell(row, col);cells[1] = new Cell(row, col+1);cells[2] = new Cell(row, col+2);cells[3] = new Cell(row+1, col+2);}}---package day02;public class TestTetrominoJ {public static void main(String[] args) {Tetromino j = new TetrominoJ(1, 2);System.out.println("-------打印J坐标 -----");j.printTetromino();}}
//重写Tetromino的print方法并测试public void print(){System.out.println("I am a J");super.print();}//测试结果是:I am a J + print出来的坐标
Foo foo = new Foo(); foo.f();这两行代码是怎样内存实现的
class Base{double size;String name;public Base(double size, String name){this.size = size;this.name = name;}}public class Sub extends Base{String color;public Sub(double size, String name, String color){super(size,name);this.color = color;}public static void main(String[] args){Sub s = new Sub(5.6, "测试对象","红色");System.out.println(s.size + "--" + s.name + "--" + s.color + "--");}}结果是:5.6--测试对象--红色--