Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8223401
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T14:40:58+00:00 2026-06-07T14:40:58+00:00

Consider this function : public boolean foo(){ System.exit(1); //The lines beyond this will not

  • 0

Consider this function :

public boolean foo(){
   System.exit(1);
   //The lines beyond this will not be read
   int bar = 1;                  //L1
   //But the return statement is required for syntactically correct code
   return false;                 //L2

   //error here for unreachable code
   //int unreachable = 3;        //L3

}

Can someone please explain why L1 and L2 visibly not reachable does not give warnings but L3 does.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-07T14:40:59+00:00Added an answer on June 7, 2026 at 2:40 pm

    Because as far as the compiler is concerned, System.exit() is just another method call.

    The fact that what it does is end the process can only be found out from the implementation (which is native code, not that it makes any difference).

    If you have to put System.exit() in your code (usually it’s best to avoid it, unless you want to return a code other than 0), it should really be in a method that returns void, main() for example. It’s nicer that way.

    As for the reachability, the explanation is the same: return is a keyword of the Java language, so the compiler or the parser the IDE uses can tell that it’s theoretically impossible for code after the return statement to be executed. These rules are defined here.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Consider the following function: public function foo(bar1:int, bar2:uint, bar3:String, bar4:Boolean):void{} What I want is
consider this simple function def foo(l=[]): if not l: print List is empty else
Consider this trivial function: public static bool IsPositive(IComparable<int> value) { return value.CompareTo(0) > 0;
Consider this function: public static final int F(int a, int b) { a =
Consider this class: class test { public function __set($n, $v) { echo __set() called\n;
Consider this template function: template<typename ReturnT> ReturnT foo(const std::function<ReturnT ()>& fun) { return fun();
Consider this code: public function showActiveJobsAction($slug) { $em = $this->getDoctrine()->getEntityManager(); $category = $em->getRepository('JobeetBundle:Category')->findBySlug($slug); if
Consider the following Java function: public void foo(Class<? extends Exception> cl, List<? extends Exception>
Consider this code sample: public abstract class Parent { public int val; public Parent()
Consider this class: class Test { public $obj; function __construct ($obj) { $this->obj =

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.