Java Interview Questions

Java Interview Questions 6

51. The Container methods add( Component comp ) and add( String name, Component comp) will throw an IllegalArgumentException
if comp is a:
a) button
b) list
c) window
d) textarea
e) container that contains
this container

52. Of the following AWT classes, which one(s) are responsible for implementing the components layout?
a) LayoutManager
b) GridBagLayout
c) ActionListener
d) WindowAdapter
e) FlowLayout

53. A component that should resize vertically but not horizontally should be placed in a:
a) BorderLayout in the North or South location
b) FlowLayout as the first component
c) BorderLayout in the East or West location
d) BorderLayout in the Center location
e) GridLayout

Java Interview Questions 5

41. For what reasons might a thread stop execution?
a) A thread with higher priority
began execution.
b) The thread’s wait() method was invoked.
c) The thread invoked its yield() method.
d) The thread’s pause() method was invoked.
e) The thread’s sleep() method was invoked.

42. Which method below can change a String object, s ?
a) equals(s)
b) substring(s)
c) concat(s)
d) toUpperCase(s)
e) none of the above will change s

43. If s1 is declared as:
String s1 =
“phenobarbital”;
What will be the value of s2 after
the following line of code:
String s2 = s1.substring( 3, 5 );
1. a) null
b) “eno”
c) “enoba”
d) “no”

Java Interview Questions 4

31. Consider the code below:
void myMethod()
{  try
{
fragile();
}
catch( NullPointerException npex )
{
System.out.println( “NullPointerException thrown ” );
}
catch( Exception ex )
{
System.out.println( “Exception thrown ” );
}
finally
{
System.out.println( “Done with exceptions ” );
}
System.out.println( “myMethod is done” );
}
What is printed to standard output if fragile()
throws an IllegalArgumentException?
a) “NullPointerException thrown”
b) “Exception thrown”
c) “Done with exceptions”
d) “myMethod is done”
e) Nothing is printed

Java Interview Questions 3

21. Which of the following are correct methods
for initializing the array “dayhigh” with 7 values?
a) int dayhigh = { 24, 23, 24, 25, 25, 23, 21 };
b) int dayhigh[] = { 24, 23, 24, 25, 25, 23, 21 };
c) int[] dayhigh = { 24, 23, 24, 25, 25, 23, 21 };
d) int dayhigh [] = new int[24, 23, 24, 25, 25, 23, 21];
e) int dayhigh = new[24, 23, 24, 25, 25, 23, 21];
22. If you want subclasses to access, but not to
override a superclass member method, what keyword should precede the name of
the superclass method?

Java Interview Questions 2

11. The statement …
String s = “Hello” +
“Java”;

yields the same value for s as …

String s = “Hello”;
String s2= “Java”;
s.concat( s2 );

True
False

12. If you compile and execute an application
with the following code in its main() method:

String s = new String( “Computer” )
if( s == “Computer” )
System.out.println( “Equal A” );
if( s.equals( “Computer” ) )
System.out.println( “Equal B” );

Pages (21): « First ... « 16 17 18 [19] 20 21 »