java-day05

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

Shoot shooting game
. .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 the super class 3. Design two structures for super class FlyingObject, 6 object classes Call the superclass to construct the fourth day of the Shoot 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 .Draw Window Shooting Game Day 5: 1. Add access control modifiers to members of the class 2. Add image properties to 6 object classes Review: 1. Upward modeling:   1) Supertype references point to objects of derived classes   2 ) What can be pointed out, look at the type of reference 2. Override of the method:   1) It occurs in the 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 object 3. The difference between overriding and overloading: 1   ) Overriding:     1.1) Occurs in the parent and child classes, the method name is the same, the parameter list is the same, and the method body is different     1.2) Runtime binding, see the object type to call the method   2 ) overload:






























    2.1) Occurs in a class, the method name is the same, the parameter list is different, and the method body is different
    2.2) Binding at compile time, see the parameter type to bind the method

Notes:
1.package:
  1) Function: Avoid class naming conflicts
  2) The full name of the class: package name. class name 3)   The package name     can
  have a hierarchical structure 4) Suggestion   :
  all letters in the package name are lowercase There are two ways to access:     1.1) First import the declared class, and then directly access the class -----Recommended     1.2) The full name of the class ----------- ----Too cumbersome, not recommended 2. Access control modifiers:   1) public: public, any class   2) protected: protected, this class, subclass, same package class   3) default: nothing Write, this class, the same package class   4) private: private, this class   description:     1) The access modifier of the class can only be public or default     2) The access modifier of the members in the class can be as above 4 types 3. final : Final, unchangeable ------- low application rate   1) Modified variables: Variables cannot be changed   2) Modified methods: Methods cannot be overridden   3) Modified classes: Classes cannot be inherited 4.static: static 1 )   Static variables:



















    1.1) Modified by static
    1.2) It belongs to the class and is stored in the method area, with only one copy
    1.3) Often accessed through the class name point
    1.4) When to use: data shared by all objects (pictures, audio, video, etc.)
  2 ) Static method:
    2.1) Modified by static
    2.2) It belongs to the class and is stored in the method area, with only one copy
    2.3) It is often accessed through the class name point
    2.4) There is no implicit this transfer
        in static methods, so it cannot be used in static methods.   Access instance         members     directly
    _ The block is only executed once     3.2) When to use: Initialize/load static resources (pictures, audio, video, etc.) 5. static final constants: tomorrow will be an exercise: 1. Ensure the normal operation of the program 2. Preview static final constants 3. Will be today The two functions are rewritten twice on the basis of yesterday. The pictures of the day's work and the day's reading are rewritten on the basis of yesterday.------------ The operation of the file IO operation on the file is particularly prone to exceptions ------- ---When java is forced to do IO operation, it must do the operation of the exception handling method-----most of which should be related to the object






















































More instance variables or more static variables---------------Multiple instance variables, more
instance methods or more static methods---------------Multiple instance methods

















Arrays. sort(arr);

No matter which object in a1, a2, a3,..., a100
goes to sort(arr), the final result is the same,
indicating that the operation of sort() has nothing to do with objects but only with parameters

Assuming sort() is not static:
  Arrays a1 = new Arrays();
  a1.sort(arr);

  Arrays a2 = new Arrays();
  a2.sort(arr);

  Arrays a3 = new Arrays();
  a3.sort( arr);












double d = Math.sqrt(25);

No matter which object in m1,m2,m3,...,m100
goes to sqrt(25), the final result is the same,
indicating that sqrt() The operation is independent of objects but only of parameters


Assume sqrt() is not static:
  Math m1 = new Math();
  double d = m1.sqrt(25); //5.0

  Math m2 = new Math();
  double d = m2 .sqrt(25); //5.0

  Math m3 = new Math();
  double d = m3.sqrt(25); //5.0
















Scanner scan = new Scanner(System.in);
int a    = scan.nextInt();
double b = scan.nextDouble(); //实例方法

double c = Math.random();
double d = Math.sqrt(25); //5
int[] a1 = Arrays.copyOf(a,6);
Arrays.sort(arr);

















1)day07中的GuessingGame类
2)oo.day01中的Student类
3)射击游戏的World类






















map.jpg---------------------图片(一份)
意外.mp4--------------------音频(一份)
战狼2.avi-------------------视频(一份)

























成员变量:
1)实例变量:没有static修饰,属于对象的,存储在堆中,
           有几个对象就有几份
           通过对象点来访问
2)静态变量:由static修饰,属于类的,存储在方法区中,
           只有一份,
           通过类名点来访问


Aoo.b = 1;
Aoo o = new Aoo();
oa = 1;

class Aoo{
  int a;
  static int b;
}


heap: new objects (including instance variables)
stack: local variables (including method parameters)
method area: .class bytecode file (including methods, static variables) )














data (variable) private (private), behavior (method) public (public)

class Card{
  private String cardId;
  private String cardPwd;
  private double balance;
 
  public boolean checkPwd(String pwd){
    if(pwd.equals(cardPwd )){
      return true;
    }else{
      return false;
    }
  }
  public boolean payMoney(double money){
    if(balance>=money){
      balance-=money;
      return true;
    }else{
      return false;
    }
  }


}




























package java.util;
class Scanner{
  Scanner(Stream s){
  }
  int nextInt(){
  }
  double nextDouble(){
  }
  String next(){
  }
}

import java.util.Scanner;
Scanner scan = new Scanner(System.in );
int a = scan.nextInt();
double b = scan.nextDouble();
String s = scan.next();
























Suggestion:
  reverse domain name . project name . module name . class name
  cn.tedu . aproject . stumanager . Student  
  cn.tedu . aproject . teachmanager .

















  cn.tedu . bproject .


Portability













  com.taobao .


Company A:
  package abc;
  class Aoo{
  }

Company B:
  package abc;
  class Aoo{
  }













package abcdefg;
class Aoo{ //a.Aoo
}

package abcdefg;
class Aoo{ //b.Aoo
}
















package to avoid class naming conflicts


Project------------ -------- Community name
package---------------------- Building number + unit number
category------------ ------------- The room


























has a window, I want to draw objects on the window, but I'm actually drawing pictures











Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=324579873&siteId=291194637