1: How to create a Help document (learn)//The construction method is private, the outside world cannot create objects, can be called with the class name PrivateArraytool () {} (1) Write a class (2) Add a document comment/*** This is a tool class for manipulating arrays *@authorZhu Jia Ting *@versionv.10*/ /** *@paramint[] Arr This is the array to get the maximum value *@returnint returns the maximum value in the array*/ (3) can be generated by Javadoc tools Javadoc-D Directory-author-version Arraytool.java to a. class file and instructions you can use the methods in the tool class2: Learned the Math Class (master) with the API provided by the JDK (1) API (Application Programming Interface) application programming interface (Help documentation) (2) How to use it?Please refer to1: Open the Help document2: Click Show, find index, see Input box3: Know who you're looking for?Take scanner Example4: Enter scanner in the input box and return5: Look at the class under the package Java.lang does not need to import, all the others need to import. To import: Java.util.Scanner6: Just take a look at the class explanation and description, and don't forget to look at the version of the class .7: Look at the structure of a class member variable field summary How to construct a method summary member method method summary8: Learn to construct method A: Create object B with constructor method: No constructor method member may be static9: See member Method A: Left static: If static, the return value type can be called through the class name: What is returned, what you receive. B: Right look at the method name: method names do not write the wrong argument list: What they want, you give what, you give a few, you gave a few (3Math Class A: is a class B that operates on mathematics: there is no constructor because its members are static C: Generating random numbers Public Static DoubleRandom (): [0.0,1.0) D: How to produce a 1-random number between 100intNumber = (int) (Math.random () *100) +1; E: Guess number games3: code block (understanding) (1code that is enclosed in {}. (2) Classification: A: Local code blocks are used to limit the life cycle of variables, release early, and improve memory utilization. B: Construct blocks of code to put the same code in multiple construction methods here, before each construction method executes, first executes the construction code block. C: Static code blocks initialize the data of the class, only once. (3) Static code block, construct code block, construct method order problem?Static code block> Building Code blocks >Construction Method4: Inherit (master) (1) to extract the same members from multiple classes into a separate class. Then let these multiple classes have a relationship with that independent class, and these classes will have the content. This relationship is called inheritance. //Defining student Classes classStudent {String name; intAge ; PublicStudent () {}//getXxx ()/setxxx ( ) Public voideat () {System.out.println (Eat); } } //Define teacher Class classTeacher {String name; intAge ; PublicTeacher () {}//getXxx ()/setxxx ( ) Public voideat () {System.out.println (Eat); } } ---------------------------------------------classperson{String name; intAge ; PublicPerson () {}//getXxx ()/setxxx ( ) Public voideat () {System.out.println (Eat); } } classStudentextendsperson{ PublicStudent () {}}classTeacherextendsPerson () { PublicTeacher () {}} (2) How is inheritance represented in Java? what is the format?A: Use keyword extends to represent B: format:classSub-class nameextendsThe parent class name {} C: Separate This class is called the parent class (also called the base class and the superclass), and the class that inherits the parent class is called a subclass (also called a derived class) (3the benefits of inheritance: A: Improved reusability of code B: Improved Code maintainability C: Let the class and class have a relationship, is the premise of polymorphism (4The disadvantage of inheritance: A: To enhance the coupling of the class. Such a change in a class will affect other classes related to that class. Principle: Low coupling, high cohesion. Coupling: A class-To-class relationship: the ability to accomplish something by itself B: Breaking the Encapsulation (5) inherited features in Java A:java class only supports single inheritance (one subclass can inherit only one parent class)classSonextendsfather,mother{}//it's wrong.multiple (Heavy) inheritance in B:java (inheritance system)classFatherextendsgrandfather{}classSonextendsfather{} (6) Inheritance considerations: A: Subclasses cannot inherit private members of a parent class B: Subclasses cannot inherit the constructor of a parent class, but can access C by super: Do not inherit for partial functionalityclassa{ PublicShow1 () {} PublicShow2 () {}}classb{ PublicShow2 () {} Publicshow3 () {}} In this case class Bextendsa{} not good, because not only have show2 and Show1,show1 may not be required by B (7) When do you use inheritance?A: The Inheritance embodies: sub-class"is a"the relationship of the parent class. B: The Assumption method (if a is a B or B is a one, you can consider inheritance) (8The membership in Java inheritance A: member variable A: the member variable name of the subclass is not the same as the member variable name in the parent class, this is too simple B: the member variable name of the subclass is the same as the member variable name in the parent class, how is this accessed? ?The subclass's method accesses the lookup order of the variable: the local scope of the subclass method is found, and is used. In the subclass of the member scope to find, there is the use. In the member scope of the parent class, it is used. If you can't find it, you'll get an error. C:num represents the local variable value of the current method, This. num represents the num of the current class member variable,Super. Num represents the difference between NUM this and super of a parent class member variable? This represents the identity of the reference super representing the parent class storage space (which can be understood as a parent class reference and can manipulate members of the parent class) Usage: Access member variable:
This. member variablesSuper. Member variable Access construction method: This(...)Super(...) To access member methods: This. Member Methods ()Super. Member method () B: Constructor method A: The constructor method of a subclass is accessed by default to access the parent class's parameterless constructor method is for subclasses to access the initialization of the parent class data B: In the parent class as How do I do without a method of constructing a non-parametric?subclasses use super to explicitly invoke the other constructs of the parameter constructor subclass through this call itself, but there must be a construct that accesses the parent class to give the parent class A parameterless construct C: Member Method A: The member method of the subclass is not the same as the member method name in the parent class, this is too simple B: the member method of the subclass is the same as the member method name in the parent class, how is this accessed??To access the lookup order of a method through a subclass object: Look in the subclass, use it in the parent class, and use it to find it. On the error (9) Two questions: the difference between A:override and overload? Can overload change the return value type?the difference between B:this and super and the respective function? (10) data initialization of the face question a: the initialization process of a class B: the construction of the child parent class C: Hierarchical initialization (11) Case: A: Student and teacher case Inheritance B: analysis and implementation of cat and dog cases
Eighth Day of Java learning