1.static final int MY_FLAG = 16; Method removeFlag takes int x and returns int value which do not contains flag MY_FLAG. Which of the following implementations are correct: A. return (x & ~MY_FLAG); B. return ~(x | MY_FLAG); C. return (x & MY_FLAG > 0 ? x-MY_FLAG : x); D. return ~(~x | MY_FLAG); 3. Which of the following declarations correctly declare an array: A. int arr1[][] = new int[10][10]; B. int arr2[] = new int[10][10]; C. int arr3[10][] = new int[10][]; D. int arr4[][] = new int[10][]; 4.String s1 = "ABCDEF"; String s2 = s1.substring(0, 3); String s3 = s1.substring(3, 6); String s4 = s2.toUpperCase() + s3.toLowerCase(); How many String objects creates this code? A. 4 B. 5 C. 6 D. StringIndexOutOfBoundsException is thrown 5. Given method which extracts and returns file extension from the given file name: static String getName(String s) { int n = s.indexOf('.'); return s.substring(n); } Which of the following statements are true? A. This method always returns a wrong extension B. This method may return a wrong extension under certain circumstances C. This method may throw unchecked exception
D. This method works fine 6.import java.io.*; import java.net.*; public class Test2Q22{ private void test() { String a = null; String b = "b"; try { // Complex processing if(a==null) throw new MalformedURLException("test"); if(b ==null) throw new EOFException("test"); // Complex processing } catch (MalformedURLException e) { System.out.println("Caught MalformedURLException"); } catch (EOFException e) { System.out.println("Caught EOFException"); } finally { try { System.out.println("End finally " + a.trim()); } catch(Exception e) { System.out.println("End finally with an exception"); } } System.out.println("End processing"); } static public void main(String[] a) { new Test2Q22().test(); } } /* Select all valid answers a) End finally b) Caught MalformedURLException c) Caught EOFException d) End finally with an exception e) End processing f) Compilation error. Cannot add try/catch block inside a finally block*/ The correct ans is b and d.Please explain.
Ajith Kallambella
Sheriff
Joined: Mar 17, 2000
Posts: 5782
posted
0
NikhilNandu, Please post only one question per thread. This will help maintain the focus of the discussion without digression. You may post as many questions as possible. Also, your name 'nikhilnandu' does not comply with the JavaRanch naming policy. Please choose one that meets the requirements. Thanks! Ajith
Open Group Certified Distinguished IT Architect. Open Group Certified Master IT Architect. Sun Certified Architect (SCEA).
I agree. Here's the link: http://ej-technologies/jprofiler - if it wasn't for jprofiler, we would need to
run our stuff on 16 servers instead of 3.