Package definition format: package package name (multi-level package names are separated by .)
Import package: When using classes under different packages, you need to write the full path of the class to simplify, use import
Import package format: import package name; such as: import com.Demo.a1; or import com.Demo.*;
If it is under the same package, you do not need to import the package import
2. Status modifier
1. final (final state)
The meaning of the final keyword: final, after it is modified, it can no longer be changed
What can be modified by final: Modified classes, modified methods, variables
Modified class:
Indicates that a class is the final class, indicating that this class cannot have subclasses (cannot be inherited by other classes)
If a class is finalized, all methods in this class cannot be overridden
Modified method: If a method is final modified, this method cannot be overridden
Modified variable:
If a variable is modified by final, it will become a constant and cannot be assigned again, only once
Can be defined and assigned at the same time; such as: final int a = 10
Definition and assignment are separated, but can only be assigned once; final int b; b = 10
Variables defined using final are called: constants and constant names should use pure uppercase letters and use underscores between multiple words: final int MAX_VAULE = 10; final int MIN = 1
Modify local variables:
The final modified variable is the data value of the basic type and will not change
If the final-modified variable is a reference type, the address value will not change, but the content in the address can be changed.
Code case:
publicclassStudent{
publicint age =21;}publicclassfinalDemo{
publicstaticvoidmain(String[] args){
//final修饰基本类型变量finalint age =30;//final int age;先修饰再赋值就不会报错// age=100;
System.out.println(age);//输出age为30//final修饰引用类型变量final Student s =newStudent();//修饰的地址值不变
s.age =200;//但内容可以改变
System.out.println(s);//输出地址值为@49e4cb85
s.age =300;
System.out.println(s);//输出地址值还是没改变为@49e4cb85
System.out.println(s.age);//输出s.age=300;// s=new Student();不能创建新的地址值}}
Two. static (static)
static keyword meaning: static; can modify member methods, member variables, member methods
Static modification features: shared access by all objects of the class