Final can be applied to the scope:
Cosmetic class: A class that uses this modifier cannot be inherited
Modifier function: The modified cannot be overridden
Cosmetic properties:
1.final decorated member variable is constant, value cannot be modified
and Java's naming convention: constants are capitalized
When the parametric uses final to modify the base type variable, the variable cannot be modified in the function
Reference type variable: cannot change address
Copy Code code as follows:
/* Final class A
{
public final void Eat () {
System.out.println ("test");
}
} */
Class A
{
}
Class B extends A
{
//test
public void Eat () {
System.out.println ("Methods that cannot override parent classes");
}
static final double pi=3.1415926
public void Test (final int x,int y) {
//x=12; Here is the immutable
y=33;
System.out.println ("x=" +x+ "y=" +y);
}
public void Test (final int[] x) {
//representing the address of an array passed over nbsp Can change the value inside
x[0]=1;
/This is also the wrong!!! X=new int[]{23};
System.out.println (x[1]);
}
}
Class Demo4
{
public static void main (string[] args
{
new B (). Test (2,3);
new B (). Test (new int[]{20,3});
A A =new a ();
b b=new B ();
System.out.println ("A is an object (instance) of B");
System.out.println ("instanceof" + (a instanceof a));
System.out.println ("instanceof" + (a instanceof B));
System.out.println ("instanceof" + (b instanceof b));
System.out.println ("instanceof" + (b instanceof A));
System.out.println ("final");
}
}