Java Tutorial
In this java code, variables are only declared but not initialized any value to the variables of different data types.
But used non initialized java variables of different data types in print statement and raised the compiler errors during compilation of java code.
class NoInitialization { public static void main(String[] args) { byte b; short s; int i; long l; System.out.println(b); System.out.println(s); System.out.println(i); System.out.println(l); } }Output:
NoInitialization.java:8: error: variable b might not have been initialized System.out.println(b);
In compiler error, explains that variable might not be initialized.
Above Java program compilation error can be fixed by initializing the java variables with default value.
class NoInitialization { public static void main(String[] args) { byte b=1; short s=10; int i=100; long l=1000; System.out.println(b); System.out.println(s); System.out.println(i); System.out.println(l); } }Output:
1 10 100 1000
Java Tutorial
Privacy Policy | Copyright2020 - All Rights Reserved. | Contact us | Report website issues in Github | Facebook page | Google+ page