当前位置:网站首页>2022-07-18 study notes of group 5 self-cultivation class (every day)
2022-07-18 study notes of group 5 self-cultivation class (every day)
2022-07-25 23:44:00 【Self cultivation class】
Catalog
Procedural and object oriented
The three major characteristics
Naming rules for identifiers :
Constructors ( Construction method )
The relationship between classes (2 Kind of )
Guide map

object-oriented
Java Is an object-oriented programming language , stay Java in , Everything is an object
( stay Linux Everything is a document )
Procedural and object oriented
Process oriented : Process oriented is to analyze the steps needed to realize the requirements , Through some methods to achieve step by step
object-oriented ( Behaviorisation ): According to the characteristics of the whole demand 、 Functional division , Encapsulate these common parts into classes ( After class instantiation, the object ), Let the object solve the problem
The three major characteristics
stay Java in , There are three aspects of object orientation ( Four ) Big features :
encapsulation
Inherit
polymorphic
abstract
Member variables
If you declare variables directly in a class , Called member variable ( Global variables ); If you declare variables in a method , It's called a local variable .
The process of creating objects , Class instantiation process , An object is also called an instance of a class
We created one Car Class object car1, This car1 Is the name of the object . Actually this car1 It's just an identifier .
Naming rules for object names : Little hump
Syntax for creating objects : Class name Object name = new Class name ( ); Class name Object name = new Constructors ( Class name ())
a key
We've learned before 8 Basic data type in
From today on, our data type More , All the classes we can meet , Including what we just created Car It's a data type .( Except for basic data types , Others are reference data types ). All classes are reference data types
· From now on , We really understand class This keyword , Used to create a class , Used to create a data type , Because a class is a data type . image car1,car2,car3......car100 It's called quoting , It points to an area in memory , Deposit Space , We call it heap .
We need to understand two memory spaces :
Stack : We store variables and basic data types ( characteristic : First in, then out ) The address is a hexadecimal string
Pile up : The initial value of the reference data type is null
Assignment except String outside , Other reference data types need new
Member method
public : Access modifier
void : no return value
run( ): Method name ( identifier )
{ }: Method body ( What does this method do )
( ): The parameter
Parameters can have multiple , The middle is separated by commas
Java The data type needs to be specified for the parameter transfer in
When declaring a method , Parameters in parentheses : Formal parameters ( Shape parameter ), It can be used as a local variable
When a method is called ,
The formal parameter is at the declaration , The argument is at the call
There are ways to return values
public
boolean: return type , After a series of operations, my method , To get a specific value , Return value , The type of return value is boolean
Return value with return xxx; Type to match
A method with a return value will get a specific value after execution , This value can be saved
In development , Most methods have return values
return keyword
return Keyword termination method continues
Returns the return value of the method
Naming rules for identifiers :
( Letter 、 Numbers 、 Underline 、 Dollar symbol 、 The number can't start )
Class name : Hump ( Capitalize all words )
Property name 、 Method name : Little hump ( Except for the first word , Other words are capitalized )
Access modifier
public Common
protected The protected , If cross package , Must be its subclass Only attributes can be decorated Method Constructor defaults
Amicable , You can access under the current package
private Private Only attributes can be decorated , Method Constructors
Member method
Method names cannot be repeated
If one method has static, To call a non static Methods , You can only create objects , Use object . Method
Ch01 c = new Ch01( ) ;
c.run( );
Adjust yourself : recursive
The problem of recursion :StackOverflowError Stack overflow ( out of memory )
Whether to use recursion in development ? If you use it , What to pay attention to ?
Method overloading (OverLoad)
Same method name
Different parameters can constitute overloads of methods
Different types of parameters
The number of parameters is different
The order of the parameters is different
Independent of return value type ; Independent of access modifier ; Independent of the method body . Method overloading is only related to parameters
Method overloading must occur in the same class
The benefits of method overloading
In order to make the functions similar or even the same methods, we can use the same name
Indefinite length parameter
Only ( at most ) There is an indefinite length parameter
The variable length parameter must be in the last position
· The essence of indefinite length parameter is array
public static int sum(int...arr){
for (int i:
arr) {
System.out.println(i);
}
return 0;
}·java.lang All classes under the package do not need to be explicitly imported , The rest needs to be guided
Constructors ( Construction method )
grammar : Access modifier Class name ( parameter list ){ }
characteristic ( characteristic ):
- Java stay new When the object , First, check whether the class corresponding to the object has a constructor , If so, what kind of constructor ; If there is no constructor , Objects cannot be built ( Create objects )
- Each class will have a default parameterless constructor
- The constructor is called when the object is instantiated
- We actually create objects through constructors
- If a constructor is declared as shown in a class , The original default built-in parameterless constructor is invalid ( Be overwritten ). If there are multiple constructors , Must overload .
The relationship between classes (2 Kind of )
1.has a The relationship between ( contain 、 Use 、 Some relationship )
eg: Man has a cat
summary
Abstract concepts need to be practiced and understood , You'll get twice the result with half the effort
边栏推荐
- 2022 Niuke multi School Game 2
- 加拿大EE通道
- typescript ts 基础知识之类
- [testing technology automated testing pytest] basic summary of pytest
- 三板斧!助你成为优秀软件工程师
- Promise asynchronous callback function
- sftp和ftp的区别
- Reduce method of array
- Matchmaker's words
- Leetcode 0919. complete binary tree inserter: array representation of complete binary tree
猜你喜欢

LeetCode 0919. 完全二叉树插入器:完全二叉树的数组表示

redis-扩展数据类型(跳跃表/BitMaps/HyperLogLog/GeoSpatial)

utility实用组件学习之swap,move,forward,exchange

Loading process such as reflection

How to solve cross domain problems

S4/hana ME21N create Po output control message button missing solution (switch EDI output mode brf+ to Nast mode)

生成随机数random学习之uniform_int_distribution,uniform_real_distribution

谷粒学苑P98踩坑 e.GlobalExceptionHandler : null

Redis basic data type (string/list/set/hash/zset)

How does JS judge whether the current date is within a certain range
随机推荐
【MUDUO】EventLoopThreadPool
This point inside the function / change this point inside the function
Write a select drop-down list
Scaffold installation
762. 二进制表示中质数个计算置位
S4/hana ME21N create Po output control message button missing solution (switch EDI output mode brf+ to Nast mode)
Anti shake and throttling
How does JS judge whether the current date is within a certain range
ArcGIS cuts TIF images (grid data) according to the vector range, merges shp files in batches, cuts vectors in the region according to the vector range, outputs the geographic coordinate system, conve
initializer_list工具库学习
JS regular expression content:
Read the field status of account in ABAP code (hidden, optional, required)
Macro task, micro task and event cycle mechanism
ES6 syntax (difference between let, const, VaR, deconstruction assignment, arrow function, residual parameters, extension method of array)
[test technology performance test LoadRunner] detailed explanation of common functions of LoadRunner
sftp和ftp的区别
TS basic data type
numeric学习之iota,accumulate
Serialize common default values and column parameters
TS function