Java Quiz
Question 51.
Read the code below carefully.
if( "String".endsWith(""))
Sytem.out.println("True");
else
System.out.println("False");
The code produces
-
True
-
False
Question 52.
Read the code below carefully.
if( "String".startsWith(""))
Sytem.out.println("True");
else
System.out.println("False");
The code produces
-
True
-
False
Question 53.
Read the code below carefully.
public class TestClass
{
public static
void main(String
Args[])
{
StringBuffer sb1 = new StringBuffer("String");
StringBuffer sb2 = new StringBuffer("String");
if(sb1.equals(sb2))
{
//lots of code
}
}
}
Is the line marked "lots of code" ever
reached?
Question 54.
Read the code below carefully.
public class NiceThreads implements Runnable
{
public void run()
{
while(true)
{
}
}
public static void main(String
args[])
{
NiceThreads
nt1 = new NiceThreads();
NiceThreads
nt2 = new NiceThreads();
NiceThreads
nt3 = new NiceThreads();
nt1.run();
nt2.run();
nt3.run();
}
}
-
The code does not compile - "nt2.run() is never reached"
-
The code compiles and runs 3 non ending non demon threads.
-
The code compiles but runs only 1 non ending, non demon thread.
Question 55.
When does the JVM exit?
-
After the main method returns.
-
After all the non demons threads created by the application complete.
-
After all the demon threads created by the application complete
-
When a thread executes System.exit();
-
When an uncaught exception is thrown in a non demon thread.
-
When an uncaught exception is thrown in a demon thread.
Question 56.
Read the following code, which is a part of
a synchronized
method of a monitor.
public synchronized void someMethod()
{
//lots of code
try
{
Thread.sleep(500);
}
catch(InterruptedException e)
{
//do some crap
here.
}
//more and more code here
}
-
The code causes compilation error - sleep cannot be called
inside synchronized methods.
-
The code causes compilation error - sleep is not a static method of
java.lang.Thread
-
The Thread sleeps for at least 500 milliseconds in this method if not
interrupted.
-
When the thread "goes to sleep" it releases the lock on the object.
-
The "sleeping" Threads always have the lock on the Object.
Question 57.
The no-argument constructor provided
by the
compiler when no constructor is explicitly provided in the code
-
is always public
-
is always "friendly"
-
always defaults to the access modifier provided for the class.
-
depends on the compilation options of javac
Question 58.
Which of the following is the direct base
class of
java.awt.AWTEvent.
-
java.lang.Object.
-
java.util.EventObect
Question 59.
Interface methods can be declared
with the
following modifiers
-
public
-
none (i.e., no access modifier).
-
private.
-
static
-
native
-
synchronized.
Question 60.
Which of the following are true about the
class defined
inside an interface
-
it is not possible in the java Laungage.
-
The class is always public.
-
The class is always static.
-
the class methods cannot call the methods declared in the interface.
-
the class methods can call only the static methods declared in the
interface.
If
you have any concerns regarding any of the questions in this page,
please
mail me NOW!
|