![]() ![]() ![]() The error message is very clear, it's saying that local variable "b" has not initialized until line 14, where it has been read, which violates the Java rule of initializing the local variable before use. The local variable b may not have been initialized You can see we are trying to access variable "b" which is not initialized in statement c = a + b, hence when you run this program in Eclipse, you will get the following error:Įxception in thread "main" java. You will not get this error if you just declare the local variable but will not use it. If the compiler believes that a local variable might not have been initialized before the next statement which is using it, you get this error. This is because Java has the rule to initialize the local variable before accessing or using them and this is checked at compile time. You won't get this error if you use an uninitialized class or instance variable because they are initialized with their default value like Reference types are initialized with null and integer types are initialized with zero, but if you try to use an uninitialized local variable in Java, you will get this error. This error occurs when you are trying to use a local variable without initializing it. ![]()
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |