1. public class Test { public void foo() { assert false; / Line 5 / assert false; / Line 6 / } public void bar() { while(true) { assert false; / Line 12 / } assert false; / Line 14 / } } What causes compilation to fail?





Ask Your Doubts Here

Type in
(Press Ctrl+g to toggle between English and the chosen language)

Comments

  • By: guest on 02 Jun 2017 01.25 am
    Option D is correct. Compilation fails because of an unreachable statement at line 14. It is a compile-time error if a statement cannot be executed because it is unreachable. The question is now, why is line 20 unreachable? If it is because of the assert then surely line 6 would also be unreachable. The answer must be something other than assert. Examine the following: A while statement can complete normally if and only if at least one of the following is true: - The while statement is reachable and the condition expression is not a constant expression with value true. -There is a reachable break statement that exits the while statement. The while statement at line 11 is infinite and there is no break statement therefore line 14 is unreachable. You can test this with the following code: public class Test80 { public void foo() { assert false; assert false; } public void bar() { while(true) { assert false; break; } assert false; } }
Show Similar Question And Answers
QA->There are 50 students in a class. In a class test 22 students get 25 marks each, 18 students get 30 marks each. Each of the remaining gets 16 marks. The average mark of the whole class is :....
QA->Average height of 10 students in a class is 150 cm. A boy of height 160 cm left the class and a boy of height 148 cm is admitted. Then what is the average height of the students in the class now?....
QA->Mycobacterium leprae causes leprosy; Corynebacterium diphtheria causes diphtheria and Vibrio comma causes?....
QA->“It is possible to fail in many ways; while to succeed is possible only in one way”?....
QA->he average weight of 16 boys in a class is 25 kg and that of the remaining 8 boys is 15 kg. Find the average weights of all the boys in the class.....
MCQ->public class Test { public void foo() { assert false; / Line 5 / assert false; / Line 6 / } public void bar() { while(true) { assert false; / Line 12 / } assert false; / Line 14 / } } What causes compilation to fail?....
MCQ->What will be the output of the program? public class Foo { Foo() { System.out.print("foo"); } class Bar { Bar() { System.out.print("bar"); } public void go() { System.out.print("hi"); } } / class Bar ends / public static void main (String [] args) { Foo f = new Foo(); f.makeBar(); } void makeBar() { (new Bar() {}).go(); } }/ class Foo ends /....
MCQ->What will be the output of the program? public class Test { public static int y; public static void foo(int x) { System.out.print("foo "); y = x; } public static int bar(int z) { System.out.print("bar "); return y = z; } public static void main(String [] args ) { int t = 0; assert t > 0 : bar(7); assert t > 1 : foo(8); / Line 18 / System.out.println("done "); } }....
MCQ->public class Test2 { public static int x; public static int foo(int y) { return y 2; } public static void main(String [] args) { int z = 5; assert z > 0; / Line 11 / assert z > 2: foo(z); / Line 12 / if ( z < 7 ) assert z > 4; / Line 14 / switch (z) { case 4: System.out.println("4 "); case 5: System.out.println("5 "); default: assert z < 10; } if ( z < 10 ) assert z > 4: z++; / Line 22 / System.out.println(z); } } which line is an example of an inappropriate use of assertions?....
MCQ->What will be the output of the program? public class Test { public static void main(String args[]) { class Foo { public int i = 3; } Object o = (Object)new Foo(); Foo foo = (Foo)o; System.out.println("i = " + foo.i); } }....
Terms And Service:We do not guarantee the accuracy of available data ..We Provide Information On Public Data.. Please consult an expert before using this data for commercial or personal use | Powered By:Omega Web Solutions
© 2002-2017 Omega Education PVT LTD...Privacy | Terms And Conditions
Question ANSWER With Solution