java - 我的带有 final 关键字的 java 代码有错误
问题描述
// final keyword usage
package workarea;
final class demo {
final int x=10;
////compile time exception here because ‘x’ is final type
System.out.println("hello modified x value is:"+ x);
final void m1()
{
int x=2;
System.out.println("hello modified x value is:"+x);
}
void m2()
{
System.out.println("hello modified m2 x value is:"+x);
}
public static void main(String abc[])
{
demo df=new demo();
System.out.println("welcome");
df.m1();
df.m2();
}
}
这是我的代码,错误是:
Exception in thread "main" java.lang.Error: Unresolved compilation problem:
at workarea.demo.main(demo.java:24)
错误消息是针对提到 main 的代码行 帮助我更正此代码
解决方案
System.out.println("hello modified x value is:"+ x);
如果您删除此行代码,您的应用程序将成功运行
推荐阅读
- vb.net - 无法删除 .xlsx 文件 - 下一步?
- php - php - 层次表中的递归函数
- android - 在缓存中保存类似按钮操作
- node.js - 我的请求 URL 指向我的 ReactJS 服务器而不是 NodeJS
- reactjs - 当用户不刷新页面而只是关闭/退出我的模式时,如何清除登录错误消息?
- instagram-api - 如何使用 Instagram Basic Display API 通过应用审核来获取我的应用?
- .net - 无法自定义日志路径
- mysql - MySql - 从同一列中提取两个不同的总和
- vapor - 需要帮助在 Vapor 3 中使用 Fluent 进行许多 <-> 匹配
- r - R如何在每次重置之前创建计数器并使其打印到新列