oo.day04

Shooting game first day:
1. Created 6 object classes and created World class test

The second day of the shooting game:
1. Add construction methods to 6 object classes and test

Day 3 of Shooting Game:
1. Design small enemy planes, large enemy planes, small bees, bullet arrays, and test
2. Design FlyingObject superclass, 6 object classes inherit respectively
3. Design two construction methods for FlyingObject superclass , The object class is called separately


Review:
1. Overload of method:
  1) Occurs in a class with the same method name, different parameter list, and different method body
  2) The compiler automatically binds the called method according to the signature of the method during compilation
2. Constructors:
    to the member variable initial value, and the class of the same name, there is no return type
    when you create an object called automatically
    if they do not write the default constructor with no arguments, write your own is no longer available by default
    can be overridden
3.this: which The object calling method refers to which object
   this. Member variable name ------------ access member variable
   this. Method name () -------------- call method
   this () --------------------- Call constructor
4. null: empty, no
       reference to any object value is null, then the reference can not be any Operated,
       if the operation occurs NullPointerException Null pointer exception
5. Reference type variable draw equal sign:
    point to the same object, will affect the
  basic type variable draw equal sign:
    assignment, will not affect

笔记:
1.引用类型数组:
  1)Student[] stus = new Student[3];
    stus[0] = new Student("zhangsan",25,"LF");
    stus[1] = new Student("lisi",26,"JMS");
    stus[2] = new Student("wangwu",28,"SD");
    stus[1].age = 36;
  2)Student[] stus = new Student[]{
      new Student("zhangsan",25,"LF"),
      new Student("lisi",26,"JMS"),
      new Student("wangwu",28,"SD")
    };
  3)int[][] arr = new int[3][];------数组的数组
    arr[0] = new int[4];
    arr[1] = new int[4];
    arr[2] = new int[4];
    arr[1][0] = 100;// Assign the first element of the second element of arr to the value 100      for (int i = 0; i < arr.length; i ++) {
  4) int [] [] arr = new int [3] [4]; // 3 rows and 4 columns

      for (int j = 0; j <arr [i] .length; j ++) {
        arr [i] [j] = (int) (Math.random () * 100);
    System.out.println (arr [i] [j]);
      }
    }
2. Inheritance:
  1) Role: code reuse
  2) Inheritance through extends
  3) Superclass / parent class: Properties and behaviors common to all derived classes
    Derived class / subclass: derived class Unique attributes and behaviors
  4) After the derived class inherits the superclass, the derived class has: derived class + superclass
  5) A superclass can have multiple derived classes,
    a derived class can only have a superclass ---- --Single inheritance
  6) Inheritance is transitive
  7) Java regulations: Before constructing a derived class, you must first construct a superclass
    derived class if no superclass constructor is called
    ------- then the default super () calls the superclass the constructor with no arguments
    derived class constructor called when the superclass
    ------- default is no longer provided
    to be positioned in the first row when the derived class constructor super () constructor calls super
3.super: means
  Usage of super object super on behalf of current object :
    1) super. Member variable name ---- access to member variables of super class
    2) super. Method name () ---------- call super class method (tomorrow)
    3) super () ----------------- call Super class construction method
1) Create class Person, including:
  1.1) Member variables: name, age, address
  1.2) Construction method: Person (3 parameters) {}
  1.3) Method: sayHi () {Output of 3 member variables Value}
2) Create class Student, inherit Person, including:
  2.1) Member variable: studentId
  2.2) Constructor: Student (4 parameters) {}
3) Create class Teacher, inherit Person, including:
  3.1) Member variable: salary
  3.2 ) Constructor: Teacher (4 parameters) {}
4) Create class Doctor, inheriting Person, including:
  4.1) Member variable: level
  4.2) Constructor: Doctor (4 parameters) {}
5) Create class Test, main ( ) In:
  5.1) Create a Student array, containing 3 elements, and say hello to traversal
  5.2) Create a Teacher array, containing 3 elements, say hello to traversal
  5.3) Create a Doctor array, containing 2 elements, say hello to traversal


class Aoo{-----------------------a
  int a;
}
class Boo extends Aoo{-----------b+a
  int b;
}
class Coo extends Boo{-----------c+b+a
  int c;
}
class Doo extends Coo{-----------d+c+b+a
  int d;
}


Student zs = new Student();
zs.stuId/study();
zs.name/age/address/eat()/sleep();

Teacher ls = new Teacher();
ls.salary/teach();
ls.name/age/address/eat()/sleep();

class Person{------------------------//超类
  String name;
  int age;
  String address;
  void eat(){}
  void sleep(){}
}
class Student extends Person{---------派生类
  String stuId;
  void study(){}
}
class Teacher extends Person{---------派生类
  double salary;
  void teach(){}
}
class Doctor extends Person{----------派生类
  String level;
  void cut(){}
}

Inheritance in the program: the 
    code can be used without writing

Inheritance in life:
1) Inheritance of property:
    You can spend your own money without earning your own money
2) Inheritance of throne:
    You can sit on your own without having to fight yourself
3) Inheritance: You can
    do your job without finding it

3: the length of arr
4: the length of each element in arr

int[][] arr = new int[3][4]; //3行4列
for(int i=0;i<arr.length;i++){
  for(int j=0;j<arr[i].length;j++){
    arr[i][j] = 100;
  }
}

int[] arr  = new int[3];
Student[] stus = new Student[3];


// Declare an array of int [], contains 3 elements
// Each element is of type int [], the default value is null
int [] [] arr = new int [3] [];
arr [0] = new int [2];
arr [1] = new int [3];
arr [2] = new int [2];
// The first element of the second element in arr is assigned the value 100
arr [1] [ 0] = 100;

arr--------------------int[][]
arr[0]-----------------int[]
arr[0][0]--------------int


int[] arr = new int[]{
  1,
  5,
  7
};

Student[] stus = new Student[]{
  new Student(),
  new Student(),
  new Student()
};


Basic type variable -------- install specific number
Reference type variable -------- install address

int[] arr = new int[3];
arr[0] = 100;

Student [] stus = new Student [3]; // Create Student array object
stus [0] = new Student (); // Create Student object


Airplane[] as = new Airplane[5];
as[0] = new Airplane();


// Declare integer array arr, contains 3 elements
// Each element is int type, the default value is 0
int [] arr = new int [3];

// Declare the Student array, which contains 3 elements
// Each element is Student type, the default value is null
Student [] stus = new Student [3];


// Declare the Airplane array as, which contains 20 elements
// Each element is of type Airplane, the default value is null
Airplane [] as = new Airplane [20];

// Declare the BigAirplane array bas, which contains 23 elements
// Each element is BigAirplane type, the default value is null
BigAirplane [] bas = new BigAirplane [23];

Bee[] bs;
Bullet[] bts;


Basic type ------------ An
array type ------------ Same type Make
your own data type

class Emp{
  String name;
  int age;
  double salary;
}

void print(String name,int age,double salary){
}


 

Published 33 original articles · praised 4 · visits 2728

Guess you like

Origin blog.csdn.net/qq_41650000/article/details/81107380