One, the object
Object: An objective thing is an object.
Object contains: attributes (Features) and methods (actions)
Two, class
Class: A collection of groups of objects that have the same properties and methods.
The relationship between classes and objects is abstract and concrete. A class is a collection of objects that are instances of a class.
Steps to define a class
1. Define Class name
2. Write the properties of the class
3, the method of writing classes
public class < class name >{
Defining Attributes Section
Define variables to describe the properties that the class has, which are called member variables of the class.
Define Method Section
Access modifier return value type method name () {
Method body
}
}
Creating and Using objects
Class Name Object name =new class name ();
Strudent Stu =new Student ();
The object name. Properties
Stu.name= "Zhang San"; Arr.length
Object name. Method Name
Stu.learn (); Input.next ();
Attention:
1. Class properties and methods name the same variable
2. When a class is defined, the member variable can be assigned or not, and when not, the system automatically assigns a default value.
A variable within a method must have an initial value assigned to it.
3. When a class is defined, the nearest value principle is when the variable defined in the method has the same name as the global variable.
Jen Baby Java basic notes and objects