//
//
//
//
//
//
//
//
*******************************************************************
[Link] By: Aiman Hanna (C) 1993 - 2015
This program illustrates the importance of variable Initialization
Notice that this program is NOT working. Why?
Key Points:
1) variable Initialization
*******************************************************************
public class Initialization1 {
public static void main(String[] args) {
double profit, principle = 1000, interestRate = 0.0625; // it is possible to initialize at creation time
int numOfYears;
// Calculate profit after the given number of years
// Notice that until this point, profit is still uninitialized
profit = principle * interestRate * numOfYears;
[Link]("The profit after " +
numOfYears + " years is: " + profit + "$.");
}
}
/* The result of compiling the program
// Using command line
==================
C:\comp248>javac [Link]
[Link]: variable numOfYears might not have been initialized
profit = principle * interestRate * numOfYears;
^
1 error
C:\comp248>
// Using Eclipse
=============
Exception in thread "main" [Link]: Unresolved compilation problems:
The local variable numOfYears may not have been initialized
The local variable numOfYears may not have been initialized
at [Link]([Link])
*/