Shooting game on the first day:
1. Created 6 object classes, created the World class to test the
Shoot shooting game Day 2:
1. Created the construction methods of 6 object classes, tested the
Shoot shooting game in the World Day 3:
1 . Design small enemy aircraft array, large enemy aircraft array, small bee array, bullet array, and test
2. Design super class FlyingObject, 6 object classes inherit super class
3. Design two structures for super class FlyingObject, 6 object classes Call the superclass to construct the
fourth day of the Shooting game:
1. Combine the small enemy aircraft array, the large enemy aircraft array, and the small bee number into an array of FlyingObject, and test
2. Rewrite step() in 6 object classes to move
3 .drawing window
review:
1. Reference type array:
Student[] stus = new Student[3]; //Create student array object
stus[0] = new Student("zhangsan",26,"LF"); //Create Student object
stus[1] = new Student("lisi",26,"LF");
int[][] arr = new int[3][];
arr[0] = new int[2];
2. Inheritance :
code reuse, extends
Super class: common Derived class: unique
derived class After inheriting the super class, the derived class has: super class + derived class
A superclass can have multiple derived classes, and a derived class can only have one superclass - single inheritance
transitivity
must construct the superclass before the
derived class is constructed. ) Adjust the superclass no-parameter construction.
If you adjust the superclass construction yourself, it will no longer be provided by default. 3.super: The usage
of super that refers to the superclass object of the current object : 1)super.Member variable name------ ------- access the member variables of the super class 2) super. method name () --------------- call the method of the super class 3) super ()---- ------------------ Call the constructor of the superclass 4.null: empty, does not point to any object If the value of the reference is null, the reference can no longer perform any operations NullPointerException occurs if the operation is performed. Notes: 1. Upward modeling: 1) The reference of the super type points to the object of the derived class 2) What can be pointed out, see the type of the reference 2. Override of the method: rewrite, Overriding 1) Occurs in parent and child classes, the method name is the same, the parameter list is the same, and the method body is different 2) When the overridden method is called, look at the type of the object 3) Follow the "two same, two small, one big" principle:---- -------Understand 3.1) Both are the same: 3.1.1) The method names are the same
3.1.2) The parameter list is the same
3.2) Two small:
3.2.1) When the return value type of the derived class method is less than or equal to the super class method
1) void, must be equal
2) base type, must be equal
3) reference type , less than or equal to
3.2.2) The exception thrown by the derived class method is less than or equal to that of the superclass method -----after the exception
3.3) One big:
3.3.1) The access authority of the derived class method is greater than or equal to the superclass method 3. The difference between
overriding and overloading:---------Common
interview questions
The parameter list is the same, the method body is different
1.2) Follow the "runtime" binding, see the type of the object to call the method
2) Overload:
2.1) It happens in a class, the method name is the same, the parameter list is different, the method body Different
2.2) Follow the "compile time" binding, see the parameter/reference type to bind the method to
draw the window
swing related:
1) JFrame: window (picture frame)
2) JPanel: panel (picture board)
C/S: client/ Server
B/S: Browser/Server--------------
class Aoo{
void show(){} you are involved in
}
class Boo extends Aoo{
void show(String name){} //overload
}
Boo o = new Boo();
o.show();
o.show("zhangsan");
OverrideOverloadDemo
Compilation time: .java is compiled , generate .class bytecode file----only check syntax
runtime: JVM loads .class and runs .class
heap, stack, method area
I inherited a Chinese restaurant:
A: I still want to make Chinese food----- ------------ No need to rewrite
B: I want to change to western food --------- Need to rewrite
C: I want to make a basic Chinese food Add western food on top ------- need to rewrite (super Chinese food, plus western food)
OverrideDemo
class World {
FlyingObject[] enemies;
FlyingObject[] enemies = null;----------- After the null pointer
FlyingObject[] enemies = {};
FlyingObject[] enemies = new FlyingObject[0];
}
FlyingObject o1 = new Airplane();
FlyingObject o2 = new BigAirplane();
FlyingObject o3 = new Bee();
FlyingObject[] enemies = new FlyingObject[3];
enemies[0] = new Airplane();
enemies[1] = new BigAirplane();
enemies[2] = new Bee();
for(int i=0;i<enemies.length;i++){
System.out.println(enemies[i].x+","+enemies[i].y);
enemies[i].step();
//被子弹射击
//和英雄机撞
}
UploadDemo
Person p1 = new Student();
Person p2 = new Teacher();
Person p3 = new Doctor();
p1.Person类中的变量和方法
FlyingObject o1 = new Airplane();
FlyingObject o2 = new BigAirplane();
FlyingObject o3 = new Bee();
FlyingObject o4 = new Bullet(100,200);
FlyingObject o5 = new Hero();
FlyingObject o6 = new Sky(); // animal in
o1.FlyingObject class
is animal
Animal o1 = new Animal();
// tiger is tiger
Tiger o2 = new Tiger();
// tiger is animal
Animal o3 = new Tiger (); //Correct
//The animal is a tiger----semantics don't make sense
Tiger o4 = new Animal(); //Compile error
class Animal{ //Animal
}
class Tiger extends Animal{ //Tiger
}
java - day04
Guess you like
Origin http://43.154.161.224:23101/article/api/json?id=324579947&siteId=291194637
Ranking