![]() |
About  | Contact  | Site Map  |  Mirror    |
| Voodoo Exam  |  Question Bank  |  Databases  |  Tutorials    |
|
    |
Objective 2 - Flow Control & Exception Handling : We have moved to a new website(www.irixtech.com) where you can now take mock exams online, come back & review your answers later, ask questions in our forums & SCJP questions ranging from SCJP 1.4 to SCJP 6.0, including these question banks & dumps from this site. Click here to be taken to our new website. Do read the disclaimer before proceeding . If you believe that any question here doesn't belong to this category bring it to my attention & I'll rectify it . Comments & suggestions will be highly appreciated . If you'd like to see your question's here mail me . 1. Will the following code compile ? If yes , what is the output & if not what is the compiler error ? class Test{
static String raid(){
try
{
throw new Exception();
}
catch (Exception e)
{
int i = 1 / 0 ;
return "Error";
}
finally
{
return "Peace";
}
}
public static void main(String args[]){
System.out.println(raid());
}
};
Options :
2. What is the compiler error generated by the following piece of code or what is the output if any ? class Test01{
public static void main(String args[]){
int i = 1;
if ( i = 2 )
{
System.out.println("In if");
}
else System.out.println("In else");
}
};
Options :
3. Will the code given below compile ? If run with the following command line - java just - what is the output ? class Test02{
public static void main(String args[]){
String str = args[0];
switch ( str.equals("just"))
{
case 1:
System.out.println("case 1");
break;
case 2:
System.out.println("case 2");
break;
default:
break;
}
}
};
Options :
4. What is the output of the following code fragment when run with the following command line - java 1 ? class Test03{
public static void main(String args[]){
int i = Integer.parseInt(args[0]);
switch (i)
{
case 1:
System.out.println("case 1");
case 2:
System.out.println("case 2");
default:
System.out.println("default");
break;
}
}
};
Options :
5. Predict the output for the following piece of code . class Test04{
public static void main(String args[]){
for ( int i = 1 ; i <= 5 ; i++ )
{
if ( i < 5 )
{
continue;
}
else System.out.println( i );
}
}
};
Options :
6. Will the following code block compile ? If yes , what is the output ? class Test05{
public static void main(String args[]){
try
{
throw new Exception();
System.out.println("try");
}
catch (Exception e)
{
System.out.println("catch");
}
finally
{
System.out.println("finally");
}
}
};
Options :
7. What is the output for this ? class Test06{
public static void main(String args[]){
for (int i = 0 ; i < 5 ; i++)
{
System.out.println(i);
break;
}
}
};
Options :
8. Will the following code generate a compiler error ? If not , what is the output ? class Test07{
public static void main(String args[]){
for (int i = 0 ; i < 5 ; i++)
{
break;
System.out.println(i);
}
}
};
Options :
9. Choose the most appropriate option for the following piece of code - class Test08{
public static void main(String args[]){
char c = 'a';
switch (c)
{
case 1:
System.out.println( "case 1" );
break;
case 2:
System.out.println( "case 2" );
break;
case 3:
System.out.println( "case 3");
break;
default:
System.out.println( "default" );
break;
}
}
};
Options :
10. Does the following piece of code compile ? If yes , what is the output ? class Test09{
static int tomb( char a){
throw new NumberFormatException();
}
public static void main(String args[]){
try
{
tomb('a');
}
catch (Exception e)
{
System.out.println("Done");
}
}
};
Options:
Answers :
|
|
© 2000-2002 Ashish Hareet |