java小白咨询下局部变量的问题
package com.iss.no1;
public class Test2 {
public static void main(String[] args) {
// TODO Auto-generated method stub
AB ab = new AB();
System.out.println("初始化:");
ab.showAB();
ab.init(6);
System.out.println("之后");
ab.showAB();
}
}
class AB{
private int a=0,b=0;
void init(int x){
a=x;
int b=5;
System.out.println("初始化:");
System.out.println("a="+a+"b="+b);
}
void showAB(){
System.out.println("a="+a+"b="+b);
}
}
运行之后结果为:
初始化:
a=0b=0
初始化:
a=6b=5
之后
a=6b=0
第三个结果为什么是这样的?