Day06
1, two-dimensional array definition format?
(1) The element is an array of one-dimensional arrays.
(2) Format:
A: Data type [] Array name = new data type [m][n];
B: Data type [] Array name = new data type [m][];
C: Data type [] Array name = new data type [][]{{...},{...},{...}};
D: Data type [] Array name = {{...},{...},{}};
------------------------------------------------------------------
2, Study questions
Parameter passing problem
Only values are passed in Java.
Basic type: Changes in formal parameters do not affect actual parameters
Reference type: Changes in formal parameters directly affect actual parameters
------------------------------------------------------------------
3. An overview of object-oriented thinking
(1) Object-oriented
Object-oriented is a process-oriented programming idea
(2) Object-oriented thought characteristics
A: It's a thought that's more in line with our thinking habits.
B: Simplifying Complex things
C: Let's turn from the executor to the conductor
------------------------------------------------------------------
4, the class and the object is what, examples illustrate
A: Things in the real world
Basic description of a property thing
The function of a behavioral thing
The most basic unit in the B:java language is the class. So, we're going to use classes to show things.
C: Class
member variables Things properties
Member Methods thing behavior
D: Class: Is a set of related properties and behaviors. is an abstract concept.
Object: is the concrete existence of this kind of thing, is a concrete instance. Object
Example: Student: Class Leader: Object
------------------------------------------------------------------
5, how to define a class, the composition of the class
The member variable definition format is the same as before, where the location is different, in the class, outside the method.
The member method definition format is the same as before, which is to remove the static.
------------------------------------------------------------------
6. How to use a member of a class
A: Create an object? Format Class Name Object name = new class name ();
B: How do I use member variables and member methods?
Object name. Member Variable
The name of the object. Member method ()
------------------------------------------------------------------
Day07
1. What is the difference between a local variable and a member variable?
(1) Different positions in the class
Member variables: Outside Methods in class
Local variables: In a method definition or on a method declaration
(2) different locations in memory
Member variables: in the heap
Local variables: in the stack
(3) Different life cycle
Member variables: As objects are created, they disappear as the object disappears
Local variables: As the method is called, it disappears as the method's call is complete
(4) different initialization values
Member variables: with default values
Local variables: No default values, must be defined, assigned, and then used
------------------------------------------------------------------
2. What is an anonymous object? What is the application scenario?
(1) An object without a name
(2) Application Scenarios
A: Call the method, just call it once.
B: Can be passed as an actual parameter.
------------------------------------------------------------------
3. What is encapsulation? What is the embodiment of encapsulation in Java? Please give an example.
(1) Hide implementation Details and provide public access
(2) Benefits:
A: Hide implementation details and provide public access
B: Improve the reusability of code
C: Improve the security of your code
(3) Design principles
Hide the implementation details that you don't want to know about, and provide a common way to access them.
(4) Private is a manifestation of encapsulation.
Encapsulation: class, method, private modifier member variable
------------------------------------------------------------------
4. What is the private key word? Application Scenarios for private keywords?
(1) Private meaning, can modify member variables and member methods
(2) Features:
Members that are modified by private can only be accessed in this class
(3) Application of private:
To write a class later:
Give all the member variables to private.
provides the corresponding getxxx ()/setxxx () method
------------------------------------------------------------------
5. What is the This keyword? What is the application scenario of this keyword?
(1) A Reference object representing the current class
Remember: Which object calls the method, and the inside of the method represents that object
(2) This application scenario:
A: Fixed the problem of local variable hidden member variable
B: In fact this has other applications, to be explained tomorrow.
------------------------------------------------------------------
6. What is the function of the tectonic method? What are the characteristics of the construction method? What are the considerations for constructing a method? Can I write a return statement in the constructor?
(1) Function: Used to initialize the data of an object
(2) Format:
A: The method name is the same as the class name
B: There is no return value type, and even void cannot have
C: no return value
(3) Considerations for construction methods
A: If we do not write a construction method, the system will provide a default parameterless construction method
B: If we give a construction method, the system will no longer provide a default construction method
If this is the case, we have to use the parameterless construction method and we have to give it ourselves.
Recommendation: Always manually give a non-parametric construction method.
(4) Can there be a return statement in the construction method
OK. It's OK if we write this way: return;
In fact, at the end of any method of void type you can write: return;
------------------------------------------------------------------
7, there are several ways to assign a member variable?
A:setxxx ()
B: With parameter construction method
------------------------------------------------------------------
8. Initialization of member variables for a class
Student s = new Student ();
(1) Load the Student.class file into memory
(2) Open space in stack memory for s
(3) Application space for student objects in heap memory
(4) Default initialization of the student's member variables. null,0
(5) Display initialization of the student's member variables. Brigitte, 27
(6) Initialize the member variables by constructing the method. Elina, 30
(7) The object is constructed, assigning the address to the S variable
------------------------------------------------------------------
9. What are the static keywords? What are the characteristics?
(1) The meaning of the static. member variables and member methods can be decorated.
(2) Static characteristics:
A: Loaded with the load of the class
B: Priority and object presence
C: Shared by all objects of the class
This is actually the basis for us to judge whether we should use static.
Examples: Problems of drinking fountains and water cups
D: Can be called by the class name
Called by the name of the object, or by the class name, is recommended by the class name.
(3) static precautions;
A: There is no this object in the static method
B: Static can only access static (code tested too)
(4) The difference between a static variable and a member variable
A: Belong to different
Static variable: Belongs to class, class variable
Member variables: belong to object, object variable, instance variable
B: Different memory locations
Static variables: Static area of the method area
Member Variable: heap memory
C: Different life cycle
Static variables: Static variables are loaded as the class is loaded and disappear as the class disappears
Member variables: Member variables are present as the object is created and disappear as the object disappears
D: Call Different
Static variables: Can be called by object name, or by class name
Member variable: can only be called by object name
------------------------------------------------------------------
10, Main method of various modifiers and parameters of interpretation?
public: Maximum Permissions
Static: Do not create object calls
void: Return value does not make sense to the JVM
Main: is a common name.
String[] args: Can receive data, flexibility of the provider
------------------------------------------------------------------
Day08
1. What is a code block? What are the categories and characteristics of code blocks?
(1) Code enclosed in {}.
(2) Classification:
A: Local code block: Used to limit the life cycle of variables, early release, improve memory utilization.
B: Construct code blocks: You can put the same code in multiple construction methods here, and first execute the construction code block before each construction method executes.
C: Static code block: 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
------------------------------------------------------------------
2. Overview of Inheritance
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.
------------------------------------------------------------------
3. The advantages and disadvantages of inheritance
(1) Benefits of inheritance:
A: Improved reusability of the code
B: Improved maintainability of the code
C: Let the class and the class have a relationship, is the precondition of polymorphism
(2) 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: Class-to-class relationships
The ability to accomplish something by oneself
B: Breaking the encapsulation
------------------------------------------------------------------
4. Characteristics of inheritance in Java
Class in A:java only supports single inheritance
Multiple (Heavy) inheritance in B:java (inheritance system)
------------------------------------------------------------------
5. Considerations for Inheritance in Java
A: Subclasses cannot inherit private members of parent class
B: Subclasses cannot inherit the constructor of a parent class, but can access it through super
C: Do not inherit for part of the function
------------------------------------------------------------------
6. Features of member access in succession
A: Member variables
Accessing a variable in a subclass method
B: Member Method
Accessing a method from a subclass object in a test class
------------------------------------------------------------------
8. The execution flow of the construction method in the inheritance? If the parent does not have a parameterless constructor, what should the subclass do?
A: The constructor of a subclass is accessed by default to access the parent class's parameterless construction method
is for subclasses to access the initialization of the parent class data
B: What if there is no parameterless construction method in the parent class?
Subclasses explicitly invoke a parameter construct with super
Subclasses use this to invoke other constructs of their own, but there must be a construct that accesses the parent class.
To have the parent class provide an argument-free construct
------------------------------------------------------------------
Day09
1. What are the final key words to do?
(1) is the final meaning, can be modified class, method, variable.
(2) Features:
A: It modifies the class and cannot be inherited.
B: It modifies the method and cannot be rewritten.
C: The variable it modifies is a constant.
------------------------------------------------------------------
2. The final key word of the face question?
A: Modifying local variables
B: Timing of initialization
A: can only be initialized once.
B: Common given values
Definition of the time. Recommended
Constructs the method.
------------------------------------------------------------------
3, what is polymorphism, what is the premise?
(1) The different states that the same object manifests at different times.
(2) The precondition of polymorphism:
A: There is a succession or realization of the relationship.
B: There are methods to rewrite.
C: There is a parent or parent interface reference to the child class object.
------------------------------------------------------------------
4. What are the characteristics of member access in polymorphic?
A: Member variables
Compile look left, run look left
B: Construction method
The construction of the subclass will have access to the parent class construction by default
C: Member Method
Compile look left, run look right
D: Static method
Compile look left, run look left
------------------------------------------------------------------
5. What are the advantages and disadvantages of polymorphism? How to solve the drawbacks of polymorphism?
(1) The benefits of polymorphism:
A: Improve the maintenance of code (inheritance embodies)
B: Improve code Extensibility (polymorphic representation)
(2) The disadvantages of polymorphism:
The parent cannot use the unique features of the child.
Phenomenon:
A child can be used as a parent, and the parent cannot be used as a child.
------------------------------------------------------------------
6. Transformation in polymorphic
A: Transition upward: from child to Parent
B: Transition down: from parent to child
------------------------------------------------------------------
7, abstract class overview and its characteristics?
(1) A method that does not have a specific method body is an abstract method. In a class, if there is an abstract method, the class must be defined as an abstract class.
(2) Characteristics of abstract classes
A: Abstract classes and abstract methods must be modified with the keyword abstract
B: Abstract classes do not necessarily have abstract methods, but classes with abstract methods must be abstract classes
C: Abstract class cannot be instantiated
D: Subclass of Abstract class
A: is an abstract class.
B: is a specific class. This class must override all abstract methods in the abstract class.
------------------------------------------------------------------
8. What are the characteristics of abstract class members?
A: Member variables--with variables, with constants
B: Construction Method--with construction method
C: Member Methods--there are abstractions, there are non-abstract
------------------------------------------------------------------
9, the small problem of abstract class
A: Abstract class has a construction method, can not be instantiated, then what is the use of the construction method?
Initialization for subclass access to the parent class data
B: What is the use of a class if it has no abstract method but is defined for abstract classes?
To keep the object from being created
C:abstract cannot coexist with which keywords
A:final conflict
B:private conflict
C:static no meaning
------------------------------------------------------------------
10, the interface overview and features?
(2) Features of the interface:
A: interface with keyword interface decoration
Interface interface Name {}
B: Class implementation interface with implements modification
Class name implements interface name {}
C: interface cannot be instantiated
D: Implementation class of the interface
A: is an abstract class.
B: is a specific class that must override all the abstract methods in the interface.
------------------------------------------------------------------
11, the interface of the characteristics of the members?
A: Member variables
can only be constants
Default modifier: public static final
B: Construction method
No construction method
C: Member Method
It can only be abstract.
Default modifier: Public abstract
------------------------------------------------------------------
Day10
1, formal parameters and return value problems
(1) Formal parameters:
Class Name: An object that requires this class
Abstract class Name: A subclass object that requires this class
Interface Name: An implementation class object that requires this interface
(2) Return value type:
Class Name: Returns the object of the class
Abstract class Name: Returns the subclass object of the class
Interface Name: An object that returns an implementation class for the interface
(3) Chain-type programming
Object. Method 1 (). Method 2 () .... Method N ();
After the call to Method 1 () is complete, an object should be used;
After Method 2 () is called, an object should be returned.
After the method n () call is complete, the object may or might not be an object.
------------------------------------------------------------------
2, the package definition and matters needing attention
(1) is actually a folder
(2) Function:
A: Distinguish between classes of the same name
B: Classification Management of classes
A: According to the function of
B: According to the module sub-
(3) Definition of package (master)
Package name;
Multi-stage packet. Separate.
(4) Precautions: (Master)
The A:package statement must be the first valid statement in the file
B: In a Java file, there can be only one package
C: If there is no package, the default is the No bag name
------------------------------------------------------------------
3. Common modifiers and combinations
Permission modifier: Private, default, Protected,public
Status modifier: static,final
Abstraction modifier: Abstract
------------------------------------------------------------------
4, the internal class overview and access characteristics
(1) The class is defined inside another class, which is called an inner class.
Example: Class B is defined in Class A, and Class B is called an inner class.
(2) Access rules for internal classes
A: Members of external classes can be accessed directly, including private
B: External class to access internal class members, you must create an object
(3) Classification of internal classes
A: Member Inner class
B: Local inner class
(4) member inner class
A:private for the security of the data
B:static for ease of access
The member inner class is not static:
The external class name. Internal class Name Object name = new External class name. New internal class name ();
The member inner class is static:
The external class name. Internal class Name Object name = new External class name. Internal class name ();
------------------------------------------------------------------
Java Review the third day