This week's book giveaway is in the Agile forum.
We're giving away four copies of Head First Agile and have Andrew Stellman & Jennifer Greene on-line!
See this thread for details.
Win a copy of Head First Agile this week in the Agile forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Miscellaneous  RSS feed

Posts: 2
  • Mark post as helpful
  • send pies
  • 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
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.
Ajith Kallambella
Posts: 5782
  • Mark post as helpful
  • send pies
  • 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.
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!