Files
javaSE-0113/day11/src/com/inmind/final01/Demo03.java

25 lines
616 B
Java
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

package com.inmind.final01;
/*
final关键字用于修饰成员变量
注意被final修饰成员变量必须【手动赋值】
成员变量:在类中方法外定义的非静态变量就是成员变量
成员位置:类中方法外
局部位置:方法中
*/
public class Demo03 {
//定义在成员位置的成员变量
final int i = 10;
final int j ;
public Demo03(){
j = 10;//注意被final修饰的变量你想先定义后赋值必须在构造方法中赋一次
}
public void method() {
System.out.println(i);
System.out.println(j);
}
}