Java Basic Course Learning notes (8)

Source: Internet
Author: User

1: How to make a Help document (learn)(1) Write a Class (2) to add a document note (3) generated by the Javadoc tool javadoc-d directory-author-version Arraytool.java How to use the Help document
1: Open Help document 2: Click on the display, locate the index, and see the Input box 3: Know who you're looking for? Take scanner Example 4: Enter scanner in the input box and return to 5: Look at the class under the package Java.lang does not need to import, all others need to import. To import: Java.util.Scanner6: Then simply look at the explanations and descriptions of the classes, and don't forget to look at the class's version 7: Look at the structure of the class member Variable field summary method of construction Method Summary member Method method Summary 8: Learn construct Method A: Create object B: No constructor method member May be static 9: 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;
2: Learning the Math class from the API provided by the JDK (master)(1) API (Application Programming Interface) application Programming Interface (Help documentation)(2) How to use it? Please refer to day08\code\02_ How to use the Help document provided by the JDK \ How to use the Help document. txt (3) Math class A: is a class that operates on math B: There is no constructor because its members are static C: Generates a random number public static Dou  ble random (): [0.0,1.0] D: How to produce a random number between 1-100 int numbers = (int) (Math.random () *100) +1; E: Guess number Games 3: Code block (understanding)(1) Code enclosed in {}.  (2) Classification: A: Local code block: local location, used to limit the life cycle of variables to limit the life cycle of variables, early release, improve memory utilization.   B: Construct code blocks: in the class of the occupant position, with the {} code, the gas call construction method before execution, will first execute the construction code block.  The same code in multiple construction methods can be put here, before each construction method executes, the construction code block is executed first.   C: Static code block: The occupant position in the class, with the {} code, except that he modifies it with static. Initializes the data for the class and executes only once.  (3) Static code block, construct code block, construct method order problem? Static code blocks > Constructing code blocks > Construction Methods +++++++++++++++++++++ Object-oriented [bottom] + +++++++++++++++++++++++ 4: Inheritance (Mastery)(1) The same members in multiple classes are extracted to define 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. (2)  How is inheritance represented in Java? what is the format? A: Use keyword extends to represent B: Format: Class subclass name extends parent class name {} (3) Benefits of Inheritance:A: Improved reusability of code B: Improved Code maintainability C: Let classes and classes have a relationship, is the premise of polymorphism (also the disadvantage of inheritance: the coupling of the class to enhance) (4) Disadvantages 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: The relationship between classes and classes: the ability to accomplish something by themselves B: Breaking the Encapsulation (5) characteristics of inheritance in JavaA:java class only supports single-inheritance B:java can be multi-layered (heavy) inheritance (Inheritance system) (6) Considerations for Inheritance:A: Subclasses cannot inherit private members of parent class (member variables and member methods) B: Subclasses cannot inherit the constructor of the parent class, but can access the C: Do not inherit for some functions (7) When do you use inheritance ?A: Inheritance embodies: is a relationship. B: Adoption of the Assumption method (8) member relationships in Java inheritanceA: 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 does this access?     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. What is the difference between this and super?
What are the differences?   This represents the corresponding reference for this class.   Super represents the identity of the parent storage space (which can be understood as a parent class reference and can manipulate members of the parent class). A: Call member variable this. member variable called member variable of this class super. Member variable called member variable of parent class B: Call constructor Method This (...) calls the constructor of this class super (...) call the constructor of the parent class C: Call member Method this. Member method calls the members method of this class super. Member method calling the parent class
B: Construction Method A: The constructor of a subclass is accessed by default to access the parent class's non-parametric constructionWhat is the method? The answer: is for subclasses to access the initialization of the parent class data (because the subclass inherits the data from the parent class and may also use the parent class's data.) Therefore, before subclasses are initialized, it is important to complete the initialization of the parent class data first. * * The first statement of each constructor method is by default: Super () B: What if there is no parameterless construction method in the parent class?If the parent class does not have a parameterless constructor, what happens to the subclass's constructor?     Error.      How to solve it?    A: Add a non-parametric constructor to the parent class B: Call the parent class by using the Super keyword to construct a method with the parameter constructor C: Subclasses use this to call other constructor methods of this class the subclass must have a constructor that accesses the parent class, otherwise the parent data is not initialized. Caveats: this (...) or Super (...)  Must appear on the first statement. If it is not placed on the first statement, it is possible to initialize the data of the parent class more than once, so it must be placed on the first statement. C: Member MethodA: 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 does this access? To access the lookup order of a method through a subclass object: Find in subclass, use in parent class to find, there is no use found, error D: Overview of method OverridesA method declaration that is identical to the parent class appears in the subclass, also known as method overrides, method replication. Usage Characteristics: If the method name is different, call the corresponding method if the method name is the same, and end up using the subclass of its own method override application: When the subclass needs the function of the parent class, and the function body subclass has its own content, you can override the parent class's methods, so that the parent class is inherited from the function, but also defines the * Method Overrides ConsiderationsA: Private methods in the parent class cannot be overridden because the parent class private method subclass cannot inherit the B: The subclass overrides the parent class method, the access permission is not lower the best is consistent C: The parent class static method, the subclass must also be overridden by a static method actually this is not a method rewrite, but the phenomenon is true, as for What is not a method of rewriting, polymorphic I will explain the subclass rewrite the parent class method, it is best to declare exactly the same. (9) Two face questions:The difference between A:override and overload?  Can overload change the return value type? What are the differences between B:this and super and their respective roles? (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 realization of cat and dog cases

Java Basic Course Learning notes (8)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.