
- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
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 Questions & Answers
- 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?
- Unreachable Code Error in Java
- What is static blank final variable in Java?
- Can we initialize blank final variable in Java
- Static and non static blank final variables in Java
- What is blank final variable? What are Static blank final variables 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?
- How to use a final or effectively final variable in lambda expression in Java?
- What are final, abstract, synchronized non-access modifiers in Java?
Advertisements