<> Object oriented day 4 :

<> First day of submarine game :

* Design 6 Class , Design World Class and test
<> Day 2 submarine game :

* to 6 Add constructor to class , And test
<> Submarine game day 3 :

* Design reconnaissance submarine array , Torpedo submarine array , Mine submarine array , Mine array , Deep water bomb array , And test
* Design SeaObject Superclass , Design 6 Class inherits superclass
* to SeaObject Two construction methods are designed ,6 Each class is called separately
<> Submarine game day 4 :

* Array of reconnaissance submarines , Torpedo submarine array , The mine submarine array is uniformly combined into SeaObject array , And test
* stay 6 Overridden in a class move() move , And test
* Draw window :3 step ----- Copy and paste
<> review :

*
Reference type array :

* Assign values to elements new once
* Access to data needs to be managed through array elements Student[] stus = new Student[3]; stus[0] = new Student(
"zhnangsan",25,"LF"); System.out.println(stus[0].name);
*
inherit :

* code reuse
* adopt extends Implement inheritance
* Superclass : Shared Derived class : Peculiar
* Derived classes can access their own , You can also access the of superclasses , But a superclass cannot access the of a derived class
* single inheritance
* Transitivity
* java regulations : A superclass must be constructed before a derived class can be constructed
* If the superclass constructor is not called in the constructor of the derived class , Default super() Call the super class parameterless constructor
* In the construction method of derived class, if you call the super class construction method , It is no longer provided by default
super() Call superclass constructor , Must be at the second level of the derived class constructor 1 that 's ok

*
super: A superclass object that refers to the current object
super Usage of :

* super. Member variable name ----------------- Accessing member variables of a superclass
* super. Method name ()--------------------- Call the method of the superclass
* super()------------------------------- Call the constructor of the superclass
<> note :

*
Upward modeling :

* A reference to a supertype points to an object of a derived class
* What can you point out , Look at the type of reference ------------- This is the rule , Just remember public class UploadDemo { public static
void main(String[] args) { Aoo o1 = new Aoo(); o1.a = 1; o1.show(); //o1.b = 2;
// Compilation error //o1.test(); // Compilation error , A superclass cannot access the of a derived class Boo o2 = new Boo(); o2.b = 1; o2.test();
o2.a = 2; // correct o2.show(); // correct , A derived class can access the of a superclass Aoo o3 = new Boo(); // Upward modeling o3.a = 1;
o3.show(); //o3.b = 2; // Compilation error //o3.test(); // Compilation error , What can you point out , Look at the type of reference } } class Aoo{
int a; void show(){ } } class Boo extends Aoo{ int b; void test(){ } }
*
Method rewriting : Rewrite

* Occurs in parent-child classes , Same method name , The parameter list is the same
* When the override method is called , Look at the type of object ------- This is the rule , Just remember class Restaurant { void Cook a meal () { Cook Chinese food } }
//1) I still want to cook Chinese food ---------------- No need to rewrite class Aoo extends Restaurant { }
//2) I want to make western food instead ------------------ Need to rewrite class Aoo extends Restaurant { void Cook a meal () { Make western food } }
//3) I'd like to add Western food to Chinese food --------- Need to rewrite ( before super Chinese food , Then add Western food ) class Aoo extends Restaurant { void Cook a meal () {
super. Cook a meal (); + Make western food } }
* Rewrite compliance " Two are the same, two are small and one is large " principle :----------- understand , They are as like as two peas.
* Two same :
* Same method name
* The parameter list is the same
* Small two :
* The return value type of the derived class method is less than or equal to that of the superclass method
* void And basic types , Must be equal
* When referencing type , Less than or equal to
* The exception thrown by the derived class method is less than or equal to that of the superclass method -------------API Shi Shuo
* One big :
* The access permission of the derived class method is greater than or equal to that of the superclass method ------------- Tomorrow
*
The difference between rewriting and overloading :----------- Common interview questions

* rewrite (override): Occurs in parent-child classes , Same method name , The parameter list is the same
* heavy load (overload): Occurs in the same class , Same method name , The parameter list is different
<> Essence note :

* Upward modeling :
* A reference to a supertype points to an object of a derived class
* What can you point out , Look at the type of reference ------------- This is the rule , Just remember
* Method rewriting (override/overriding): Rewrite
* Occurs in parent-child classes , Same method name , The parameter list is the same
* When the override method is called , Look at the type of object ------- This is the rule , Just remember
* Rewrite compliance " Two are the same, two are small and one is large " principle :----------- understand , They are as like as two peas.
* Two same :
* Same method name
* The parameter list is the same
* Small two :
* The return value type of the derived class method is less than or equal to that of the superclass method
* void And basic types , Must be equal
* When referencing type , Less than or equal to
* The exception thrown by the derived class method is less than or equal to that of the superclass method -------------API Shi Shuo
* One big :
* The access permission of the derived class method is greater than or equal to that of the superclass method ------------- Tomorrow
* The difference between rewriting and overloading :----------- Common interview questions
* rewrite (override): Occurs in parent-child classes , Same method name , The parameter list is the same
* heavy load (overload): Occurs in the same class , Same method name , The parameter list is different
<> supplement :

* Significance of upward modeling :-------- Realize code reuse
* When multiple roles can do the same thing , You can shape those characters into a superclass array , Unified access
* Tomorrow words :1)override: rewrite 2)package: package 3)import: Import 4)public: Open 5)protected: Protected 6)
private: Private 7)card: card 8)id: number 9)password/pwd: password 10)balance: balance 11)pay: payment 12)money:
amount of money 13)check: inspect 14)static: Static 15)image: picture 16)icon: Icon 17)get: obtain 18)status: state
<> practice :
--------------------- Write in ooday05 In the bag 1. establish Person class , contain : //------------ The following classes must be written in different files
1) Member variable :name,age,address 2) Construction method :Person(3 Parameters ){ assignment } 3) method :sayHi(){ output 3 Data } 2.
Create student class Student, inherit Person, contain : 1) Member variable : Student number stuId(String) 2) Construction method :Student(4 Parameters ){ super Overshoot class 3
Parametric structure , assignment stuId} 3) method : rewrite sayHi(){ output 4 Data } 3. Create teacher class Teacher, inherit Person, contain : 1) Member variable : wages
salary(double) 2) Construction method :Teacher(4 Parameters ){ super Overshoot class 3 Parametric structure , assignment salary } 3) method : rewrite sayHi(){ output 4
Data } 4. Create Doctor class Doctor, inherit Person, contain : 1) Member variable : title level(String) 2) Construction method :Doctor(4 Parameters ){
super Overshoot class 3 Parametric structure , assignment level } 5. Create test class Test,main in : 1) establish Person array ps, contain 5 Elements , Assign values to elements ( student , teacher , doctor ),
Traverse the output name and say hello

Technology
©2019-2020 Toolsou All rights reserved,
【C++ Must see for entry 】C++ from 0 reach 1 Introductory programming axios Interceptor packaging and use Spring Boot Interview must ask : Automatic configuration principle VMware 16 install centos 7 Detailed tutorial C Language data structure - Sequence table delete duplicates V2.0.0 The 12th Blue Bridge Cup c++b Group personal problem solving On sending data from serial port single chip microcomputer to upper computer centos7 install RabbitMqjava Polymorphic array of opencv-python Fourier transform and inverse transform