Ans B Ex110 Given public class App private boolean flag public void

Ans b ex110 given public class app private boolean

This preview shows page 70 - 77 out of 82 pages.

. Ans: B Ex.110 Given: public class App{ private boolean flag ; public void displayResult( ){ int result = flag ? 5 : 10 ; System.out.print(“Result = ” + result++) ; } public static void main(String[ ] args ){ new App( ).displayResult( ); } } What is the result? A. Compilation fails
Image of page 70
B. Result = 5 C. Result = 6 D. Result = 10 E. Result = 11 Ans: D Ex.111 Given: public class Test{ public static void main(String [] args){ char [] arr = {97, ‘\t’ , ‘e’ , ‘\n’ , ‘i’ , ‘\t’ , ‘o’ }; for(char var : arr){ System.out.print(var) ; } System.out.print(“\nThe length is :” + arr.length) ; } } What is the result? A. a e The length is : 2 B. a e i o The length is : 4 C. aeio The length is : 4 D. a e i o The length is : 7 E. Compilation fails Ans: D Ex.112
Image of page 71
Given : public class Series{ private boolean flag ; public void displaySeries( ){ int num = 2 ; while(flag) { if(num % 7 == 0) flag = flase; num += 2 ; } } public static void main(String [ ] args ){ new Series( ).displaySeries( ) ; } } What is the result? A. 2 4 6 8 10 12 B. 2 4 6 8 10 12 14 C. Compilation fails D. The program prints multiples of 2 infinite times E. The program prints nothing Ans: E Ex.113 Given: public class Test{ public void getInfo( ){ System.out.println(“Java SE 7 ”) ; } public static void main(String[ ] args){ Test obj; obj.getInfo( ) ; } }
Image of page 72
What is the result? A. Compilation fails B. A NullPointerException is throw at rutime C. The code executes and prints Java SE 7 Ans: A Ex.114 Given: class MarksOutOfBoundsException extends IndexOutOfBoundsException{ } public class GradingProcess{ void verify(int marks)throws IndexOutOfBoundsException{ if(marks > 100){ throw new MarksOutOfBoundsException( ) ; } if(marks > 50){ System.out.println(“Pass”) ; }else{ System.out.println(“Fail”) ; } } public static void main(String [ ] args){ int marks = Integer.parseInt(args[2]) ; try{ new GradingProcess( ).verify(marks) ; }catch(Exception e ){ System.out.print(e.getClass( )) ; } } } And the command line Invocation : java GradingProcess 89 50 104
Image of page 73
What is the result? A. Pass B. Fail C. class MarksOutOfBoundsException D. class IndexOutOfBoundsException E. class Exception Ans: C Ex.115 Given: public class App{ public static void main(String[ ] args){ int[ ] arr = {1 , 3 , 5 , 7} int var = 1 ; for(var: arr){ System.out.println((var++) + “ ”) ; } } } What is the result? A. 3 5 7 B. 4 6 8 C. 1 3 5 7 D. 2 4 6 8 E. Compilation fails Ans: E Ex.116 Given: public class X{ String str = “deault”; int value = 17 ; X(String s ){ str = s ;} X(int i ){value = i ;}
Image of page 74
void print(){ System.out.println(str + “ ” + value) ; } public static void main(String [] args){ new X(“hello”).print( ) ; new X(92).print( ); } } What is the result? A. default 17 hello 92 B. hello 17 default 92 C. hello 17 default 92 D. default 92 hello 17 E. Compilation this F. An exception is thrown at run time Ans: C Ex.117 Given: public class App{ private static int num ; static { num = 3 ; } static { num = 4 ; } static void findSquare(int num){ num = num * num ; }
Image of page 75
public static void main(String[ ] args ){ findSquare(num) ; System.out.println(“Result = ” + num) ; } What is the result? A. Result = 3 B. Result = 4 C. Result = 9 D. Result = 16 E. Compilation fails Ans: B Ex.118 Given: public class App{ public static void main(String [] args){ int [] [] arr = { {2 , 3 , 5 , 7} , {11 , 13 , 17 , 19} , {23 , 29}, {31 , 37}, {41 , 43 , 47} } ; System.out.print(“The length is “ + arr.length + ” .“) ; } } What is the result?
Image of page 76
Image of page 77

  • Left Quote Icon

    Student Picture

  • Left Quote Icon

    Student Picture

  • Left Quote Icon

    Student Picture