
- Java Tutorial
- Java - Home
- Java - Overview
- Java - Environment Setup
- Java - Basic Syntax
- Java - Object & Classes
- Java - Constructors
- Java - Basic Datatypes
- Java - Variable Types
- Java - Modifier Types
- Java - Basic Operators
- Java - Loop Control
- Java - Decision Making
- Java - Numbers
- Java - Characters
- Java - Strings
- Java - Arrays
- Java - Date & Time
- Java - Regular Expressions
- Java - Methods
- Java - Files and I/O
- Java - Exceptions
- Java - Inner classes
- Java Object Oriented
- Java - Inheritance
- Java - Overriding
- Java - Polymorphism
- Java - Abstraction
- Java - Encapsulation
- Java - Interfaces
- Java - Packages
- Java Advanced
- Java - Data Structures
- Java - Collections
- Java - Generics
- Java - Serialization
- Java - Networking
- Java - Sending Email
- Java - Multithreading
- Java - Applet Basics
- Java - Documentation
- Java Useful Resources
- Java - Questions and Answers
- Java - Quick Guide
- Java - Useful Resources
- Java - Discussion
- Java - Examples
Unreachable statement using the non-final variable in Java
Following is an example, wherein we will see unreachable statement using the non-final variable −
Example
class Demo_example { int a = 2, b = 3; void display_msg(){ while (a < b){ System.out.println("The first variable is greater than the second"); } System.out.println("This is an unreachable statement"); } } public class Demo{ public static void main(String args[]){ Demo_example my_instance = new Demo_example(); my_instance.display_msg(); } }
Output
“The first variable is greater than the second” displayed infinitely
A class named Demo_example, that defines two variables. Then a function named ‘display_msg’ is defined, and the two variables are checked for their equality. Relevant message is displayed on the console. Another function named ‘Demo’ contains the main function, where an instance of the ‘Demo_example’ class is created. The ‘display_msg’ is called on this instance and the relevant output is displayed on the console.
- Related Articles
- Unreachable statement using final variable in Java
- Final variable in Java
- final local variable in Java
- Instance variable as final in Java
- What is a final variable in java?
- What is static blank final variable in Java?
- Can we initialize blank final variable in Java
- Unreachable Code Error in Java
- What is blank final variable? What are Static blank final variables in Java?
- How to use a final or effectively final variable in lambda expression in Java?
- What is a blank uninitialized final variable in java?
- What is blank or uninitialized final variable in Java?
- What are unreachable blocks in java?
- Static and non static blank final variables in Java
- What are unreachable catch blocks in Java?

Advertisements