Home  >  Q&A  >  body text

Mine is jdk1.8. After the variable is modified by final, the variable can be modified in the subclass and the compilation is successful. Why?

 class Fu{

//public int x=10;

final public  int j=20;

public  void show(){

System.out.println("Fu show()");

}

}


class  Zi extends Fu {

 

public void show(){

//int x=100;

int j=200;

System.out.println("Zi show()");

//System.out.println(x);

System.out.println(j);

}

}


class FinalDemo1 {

public static void main(String[] args){

Zi z= new Zi();

z.show();

 

}

}


伟仔伟仔2491 days ago1517

reply all(0)I'll reply

No reply
  • Cancelreply