为什么访问说明符不能用于在 Java 类中的方法内部声明的变量? [英] Why access specifiers can't be used for variables declared inside method in a Java Class?

查看:12
本文介绍了为什么访问说明符不能用于在 Java 类中的方法内部声明的变量?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

为什么我们不能对在 Java 类中的方法内部声明的变量使用访问说明符?

Why we can't use access specifiers for variables declared inside method in a Java Class?

推荐答案

因为它没有意义.方法中声明的变量是该方法的局部变量;即无法在方法之外访问它们.修改变量的声明会实现什么?

Because it doesn't make sense. Variables declared in a method are local to the method; i.e. they can't be accessed outside the method. What would modifying the variable's declaration achieve?

这篇关于为什么访问说明符不能用于在 Java 类中的方法内部声明的变量?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆