Java ' final' keyword



  • When I have declared instance variable x as final then why its not showing an error when I used x variable again in Add() method although it has been declared as final ?0_1568302368580_Screenshot_20190912-204609_Gallery.jpg ?



  • Firstly I would like to highlight the fact that global and local variables CAN have same names however its not usually a good practice. Coming to the point this is a case of accessibility. You are having same names of variable but only the local variable is accessible in the Add() method so you are not getting any error.


Log in to reply
 

Powered by dubbtr | @2019

Looks like your connection to dubbtr was lost, please wait while we try to reconnect.