//inheritance Disadvantage: Break the encapsulation. /*Final keyword: 1,final is a modifier that can be used to modify classes, methods, and variables. 2,final-Modified classes cannot be inherited. 3,final-Modified methods cannot be overridden. A variable modified by 4,final is a constant that can be assigned only once. Why use final modifier variables. In fact, in the program if a data is fixed, then the direct use of this data can be, but so poor reading, so it is the name of the data. And the value of this variable name cannot be changed, so add final fixed. Specification: Constant All letters are capitalized, multiple words, in the middle with _ connection. */classfu{/*Final*/ voidmethod () {//The resources of the underlying system are called. }}classZiextendsfu{ Public Static Final DoubleMY_PI = 3.14; Static Final intx = 7; voidmethod () {//Final int x = 9;//x = 9; Final intNumber = 9; System.out.println (MY_PI); }}classFinaldemo { Public Static voidMain (string[] args) {System.out.println ("Hello world!"); }}
Inheritance disadvantage: Break the encapsulation.
/*
Final keyword:
1,final is a modifier that can be used to modify classes, methods, and variables.
2,final-Modified classes cannot be inherited.
3,final-Modified methods cannot be overridden.
A variable modified by 4,final is a constant that can be assigned only once.
Why use final modifier variables. Actually in the program if a data is fixed,
So it is possible to use this data directly, but the reading is poor, so it has the name of the data.
And the value of this variable name cannot be changed, so add final fixed.
Specification: Constant All letters are capitalized, multiple words, in the middle with _ connection.
*/
Class Fu
{
/*final*/void Method ()
{
The resources of the underlying system are called.
}
}
Class Zi extends Fu
{
public static final Double my_pi = 3.14;
static final int x = 7;
void Method ()
{
Final int x = 9;
x = 9;
Final int number = 9;
System.out.println (MY_PI);
}
}
Class Finaldemo
{
public static void Main (string[] args)
{
System.out.println ("Hello world!");
}
}
Final Java Basics Review