Java object oriented basic teaching of 1
- 2021-10-16 01:45:13
- OfStack
1. How to define a class
Syntax:
Access modifier class class name {
}
public class skills{
}
2. How to define attributes
Syntax:
Attributes are written in the class
Data type variable name;
public class hero{
String sex;
String name;
}
3. How to define a common approach
Syntax:
Access modifier return value method name (parameter) {
}
public void attack(){
Circulatory body ;
}
4. How do I create an object
Syntax:
Class name Object name = new class name ();
5. How to define constructors
Syntax:
The constructor has no return value, and the method name must remain 1 with the class name.
Constructor creates an object automatically calling
public class hero{
public hero(){
Circulatory body ;
}
}
6. What are variable parameters and how to use them?
The bottom layer of variable parameters is an array. According to the number of parameters passed, arrays with different lengths will be created to store the number of parameters passed by these parameters, which can be 0 (not passed) or multiple.
Declaration syntax:
public static void testVarargs(String...users){
}
Invoke syntax:
testVarargs ("Parameter 1", "Parameter 2"...);
Summarize
This article is here, I hope to help you, and I hope you can pay more attention to more content of this site!