1) Will this work?
public static void main(String args[])
{
RuntimeException re;
throw re;
}
Ans -> No , compile time exception :: variable re may not have been initialized
-------------------------------------------------------------------------------------------------------------
2) NumberFormatException is a subclass of IOException
-------------------------------------------------------------------------------------------------------------
3) if ("string".toUpperCase() =="STRING")
{
System.out.println("Yes");
}
else System.out.println("No");
Ans -> No // if we use .equals() here , then we get “yes” . This is because , “string” and “STRING” are two separate object references pointing to two separate objects. == is used to compare whether two object references point to same object or not. .equals() compares the objects for their contents.
-------------------------------------------------------------------------------------------------------------------
3) when we extend a class , the static class variables are also passed on to the child class. Final class variables are not passed. Transient class variables are passes( they are implicitly initialized ).
--------------------------------------------------------------------------------------------------------------------
4) We cannot extend a math class ( its final) . all its constants and methods are static.
---------------------------------------------------------------------------------------------------------------------
5) We cannot instantiate a math class .. its constructors are private.
---------------------------------------------------------------------------------------------------------------------
5) class XTC {
public static void main ( String [ ] ka ) {
int s = 64 / 9 ;
float f = 64 / 9 ;
double d = 64 / 9 ;
System . out . println ( s + " & " + f + " & " + d ) ;
}
};
Ans -> 7 , 7.0 , 7.0
---------------------------------------------------------------------------------------------------------------------
6) What is the output of the following ? Will it compile at all ?
class XTC {
public static void main ( String [ ] ka ) {
Integer b = new Integer(3) ;
System . out . println ( b instanceof Integer ) ;
}
};
Ans -> true
-----------------------------------------------------------------------------------------------------------------------
7) What is the output of the following ? Will it compile at all ?
class XTC {
public static void main ( String [ ] ka ) {
Integer b = null;
System . out . println ( b instanceof Integer ) ;
}
};
Ans -> false
--------------------------------------------------------------------------------------------------------------------
8) What is the output of the following ? Will it compile at all ?
class XTC {
public static void main ( String [ ] ka ) {
Integer b = null;
System . out . println ( b instanceof Object ) ;
}
};
Ans -> false
------------------------------------------------------------------------------------------------------------
9) What is the output of the following ? Will it compile at all ?
class XTC {
public static void main ( String [ ] ka ) {
Integer b = new Integer(3);
System . out . println ( b instanceof Object ) ;
}
};
Ans -> true
------------------------------------------------------------------------------------------------------------------------
10) if (Double . POSITIVE_INFINITY == Double . POSITIVE_INFINITY )
{
System . out . println ( “Yes”) ;
}
Ans -> Yes
--------------------------------------------**********************---------------------------------------------
Saturday, December 22, 2007
Mock Questions for Test Preparation
Posted by javaexpert at 5:30 AM 0 comments
Labels: Mock Question and Answers
Subscribe to:
Posts (Atom)