版权声明:本文为博主原创文章,未经博主允许不得转载 https://blog.csdn.net/qq_24644517/article/details/82765962
package Tets08;
/** A:案例演示
* 方法内部或者方法声明上都演示一下(了解)
* 基本类型,是值不能被改变
* 引用类型,是地址值不能被改变,对象中的属性可以改变*/
class Tets7_Final {
public static void main(String[]args){
final int num=10;
// num=20;//基本数据类型,值不能被改变
System.out.println(num);
final Person p=new Person("张三",23);
// p=new Person("李四",24);//引用数据类型,地址值不能被改变,其中对象的属性可以被改变
p.setAge(23);
p.setName("李四");
System.out.println(p.getAge()+"...."+p.getName());
method(20);
method(30);
}
public static void method(final int x){//方法声明上
System.out.println(x);
}
}
class Person{
private String name;
private int Age;
public Person(){
}
public Person(String name,int Age){
this.name=name;
this.Age=Age;
}
public void setAge(int Age) {
this.Age=Age;
}
public int getAge() {
return this.Age;
}
public void setName(String name) {
this.name = name;
}
public String getName() {
return this.name;
}
}