The Unreachable statements refers to statements that won?t get executed during the execution of the program are called Unreachable Statements. These statements might be unreachable because of the following reasons:
Scenarios where this error can occur:
Example:
class dEe {     public static void main(String args[])     {           System.out.println("It will be printed");           return;           // it will never run and gives error         // as unreachable code.         System.out.println("I want to get printed");     } } Compile Errors:
prog.java:11: error: unreachable statement
System.out.println(“I want to get printed”);
^
1 error
Example:
class GFG {     public static void main(String args[])     {         int a = 2;         for (;;) {               if (a == 2) {                   break;                   // it will never execute, so                 // same error will be there.                 System.out.println("I want to get printed");             }         }     } }  | 
Compile Errors:
prog.java:13: error: unreachable statement
System.out.println(“I want to get printed”);
^
1 error
If you like dEexams.com and would like to contribute, you can write your article here or mail your article to admin@deexams.com . See your article appearing on the dEexams.com main page and help others to learn.