Runtime vs. Compile time

前端 未结 27 1375
后悔当初
后悔当初 2020-11-22 06:50

What is the difference between run-time and compile-time?

27条回答
  •  无人共我
    2020-11-22 07:37

    Look into this example:

    public class Test {
    
        public static void main(String[] args) {
            int[] x=new int[-5];//compile time no error
            System.out.println(x.length);
        }}
    

    The above code is compiled successfully, there is no syntax error, it is perfectly valid. But at the run time, it throws following error.

    Exception in thread "main" java.lang.NegativeArraySizeException
        at Test.main(Test.java:5)
    

    Like when in compile time certain cases has been checked, after that run time certain cases has been checked once the program satisfies all the condition you will get an output. Otherwise, you will get compile time or run time error.

提交回复
热议问题