• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
  • Mikalai Zaikin


Posts: 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
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
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
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.
Posts: 5782
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
    Bookmark Topic Watch Topic
  • New Topic