Professional Documents
Culture Documents
In the following code what will be the output if 0 (integer value zero) is passed to
loopTest()?
(See Exhibit)
public class TestClass
{
public void loopTest(int x)
{
loop: for (int i = 1; i < 5; i++)
{
for (int j = 1; j < 5; j++)
{
System.out.println(i);
if (x == 0) { continue loop; }
System.out.println(j);
}
}
}
}
It will print 1 2 3 4.
It will print 1 1 2 3 4
It will print 1 1 2 2 3 3 4 4
Produces no output
Question 2 of 61
Which line contains a valid constructor in the following class definition?
Question 12 of 61
Given the following class, which statements can be inserted at line 1 without causing the
code to fail compilation?
public class TestClass
{
int a;
int b = 0;
static int c;
public void m()
{
int d;
int e = 0;
// Line 1
}
}
a++;
b++;
c++;
d++;
e++;
Question 13 of 61
Which lines contain a valid constructor in the following code?
public class TestClass
Select 1 correct option.
a
javajava
lavajava
javajavac
lavajavac
None of these.
Question 24 of 61
Consider the following class:
Which of the following statements are correct regarding the above class?
import java.util.*;
public class Info
{
String s1, s2, s3;
public Info(String a, String b, String c)
{
s1=a; s2=b; s3=c;
}
public boolean equals(Object obj)
{
if(! (obj instanceof Info) ) return false;
Info i = (Info) obj;
return (s1+s2+s3).equals(i.s1+i.s2+i.s3);
}
public int hashCode()
{
return s1.hashCode();
}
public static void main(String[] args)
{
Question 35 of 61
What will be the result of attempting to compile and run the following program?
public class Test extends Thread
{
String msg = "default" ;
public Test(String s)
{
msg = s;
}
public void run()
{
System.out.println(msg);
}
public static void main(String args[])
{
new Test("String1").start();
new Test("String2").start();
System.out.println("end");
}
}
No order is guaranteed.
class SubClass extends BaseClass
{
public void print(String s)
{
System.out.println("SubClass :"+s);
// Line 1
}
public static void main(String args[])
{
SubClass sc = new SubClass();
sc.print("location");
} }
---------------
Question 44 of 61
Consider the following situation:
Thread T1 holds the lock for an object Obj. Thread T2 is has called obj.wait() and is
blocked.
What will allow the thread T2 to become runnable?
Thread T1 is interrupted.
Thread T1 releases the lock on Obj and calls the notify() method on T2.
Thread T1 releases the lock on Obj and calls the notify() method on Obj.
Question 45 of 61
a
InitTest() { si += 10; }
{ i = 1000; }
Question 54 of 61
Consider:
o1 and o2 denote two different object references to different objects of same class.
Which of these statements are true?
o1 == o2 is always false.
Question 1 of 61
What is the result of executing the following fragment of code:
boolean b1 = false;
boolean b2 = false;
if (b2 != b1 = !b2)
{
System.out.println("true");
}
else
{
System.out.println("false");
}
Runtime error.
Question 2 of 61
Consider the following classes...
(See Exhibit)
Which of the following method declarations would be valid at line //1 ?
class Teacher
{
void teach(String student)
Question 13 of 61
Which of the following statements are true?
Question 14 of 61
In the following code, after which statement (earliest), the object originally held in s, may
be garbage collected ?
Assume that there is a Student class with appropriate methods.
(See Exhibit)
1. public class TestClass
{
2. public static void main (String args[])
{
3. Student s = new Student("Vaishali", "930012");
4. s.grade();
5. System.out.println(s.getName());
6. s = null;
7. s = new Student("Vaishali", "930012");
8. s.grade();
9. System.out.println(s.getName());
10 s = null;
}
Question 25 of 61
Which of the following methods are available in the java.lang.Math class?
double log(double a)
double log10(double a)
double rint(double a)
Question 26 of 61
Which of the following are valid declarations of the standard main() method?
The class will fail to compile, since the class Inner has not yet been declared when
referenced in class TopClass.
The class will fail to compile, since you cannot write 2 classes in the same file.
The class will fail to compile, since the class Inner must be defined in a file called
Inner.java
Question 38 of 61
Expression ( s instanceof java.awt.Point ) will return false if 's' was declared as a
variable of class java.lang.String.
a
True
False
Question 49 of 61
What would be printed during execution of the following program?
public class TestClass
{
public static void main(String args[ ] )
{
shiftTest(1, "A" ) ;
shiftTest(1<<31, "B") ;
shiftTest(1<<30, "C") ;
shiftTest(-1, "D" ) ;
}
public static void shiftTest(int i , String str)
{
if (( i >> 1) != (i >>> 1)) System.out.println(str) ;
}
}
d
Select 2 correct options
a
Question 61 of 61
Which of the following statements is correct?
One of the constructors of each class is called as a result of constructing an object of class
C.
Question 2 of 61
Question 13 of 61
What will be the output of the following program?
public class TestClass
{
public static void main(String args[ ] )
{
int i = 0 ;
boolean bool1 = true ;
boolean bool2 = false;
boolean bool = false;
bool = ( bool2 & method1(i++) ); //1
bool = ( bool2 && method1(i++) ); //2
bool = ( bool1 | method1(i++) ); //3
bool = ( bool1 || method1(i++) ); //4
System.out.println(i);
}
public static boolean method1(int i)
{
return i>0 ? true : false;
}
}
It will print 1.
It will print 2.
It will print 3.
It will print 4.
It will print 0.
Question 25 of 61
Empty file is a valid source file.
True
False
Question 26 of 61
Which of the following are true about the "default" constructor?
It is provided by the compiler only if the class does not define any constructor.
e
a
Question 37 of 61
Which interface would you use to represent collection having non-unique objects in order?
(Do not uses spaces or other special characters)
Question 38 of 61
Which of the following will compile without any error?
It will print 1.
It will print 3.
It will print 4
Question 49 of 61
The following code snippet will print 4.
int i1 = 1, i2 = 2, i3 = 3;
int i4 = i1 + (i2=i3 );
System.out.println(i4);
True
False
Question 60 of 61
Which of the following classes extend the java.lang.Number class?
java.lang.Integer
java.lang.Byte
java.lang.Character
java.lang.Double
java.lang.Short
Question 61 of 61
Which of the following is not a legal Java identifier?
num
int123
Question 1 of 61
Which of the following correctly declare a variable which can hold an array of 10 integers?
int[ ] iA
int[10] iA
int iA[ ]
Object[ ] iA
Object[10] iA
Question 2 of 61
Consider the following class :
class Test
{
public static void main(String[] args)
{
for (int i = 0; i < 10; i++) System.out.print(i + " "); //1
for (int i = 10; i > 0; i--) System.out.print(i + " "); //2
int i = 20; //3
System.out.print(i + " "); //4
}
}
Question 12 of 61
Which of the following are correct ways to initialize the static variables MAX and
CLASS_GUID ?
class Widget
{
static int MAX; //1
static final String CLASS_GUID; // 2
Widget()
{
//3
}
Widget(int k)
{
//4
}
}
3*2^2
3<2
3<<2
3<<<2
3*4
Question 23 of 61
Which of the following statements are true?
For any non-null reference o1, the expression (o1 instanceof o1) will always yield true.
For any non-null reference o1, the expression (o1 instanceof Object) will always yield
Question 34 of 61
Which of the following statements are true?
Question 35 of 61
What is the name of the method that threads can use to pause their execution until
signalled by another thread to continue ?
(Do not include a parameter list or brackets or semicolon.)
Select 1 correct option.
a
1, 3
4, 5
2, 3
1, 2, 3
Question 46 of 61
Consider the following code that uses an assertion to ensure that the program is supplied
with 2 arguments:
public class TestClass
{
public static void main(String[] args)
{
assert args.length == 2 : "Must give two arguments";
...
}
}
Which of the given statements regarding the above code are correct?
b
Question 57 of 61
Which interfaces does java.util.Hashtable implement?
java.util.SortedSet
java.util.Map
java.util.SortedMap
java.util.TreeMap
java.util.List
Question 58 of 61
Given the following class definition:
class A
{
protected int i;
A(int i) { this.i = i; }
}
Which of the following would be a valid inner class for this class?
A compilation error will be encountered at (1), since constructors should not specify a
return value.
A compilation error will be encountered at (2), since the class does not have a default
constructor.
It will not compile because parameter type of the constructor is different than the type of
value passed to it.
Question 2 of 61
What will be the output of the following program ?(See Exhibit)
class Test
Question 13 of 61
Which statements, when inserted at line 1, will cause a runtime exception ?
class B {}
class B1 extends B {}
class B2 extends B {}
public class ExtendsTest
{
public static void main(String args[])
{
B b = new B();
B1 b1 = new B1();
B2 b2 = new B2();
// insert statement here
}
}
b = b1;
b2 = b;
b1 = (B1) b;
b2 = (B2) b1;
b1 = (B) b1;
Question 14 of 61
Which statments about the output of the following programs are true?
Select 1 correct option.
a
Compilation error.
Runtime error.
Question 25 of 61
What application requirements may need you to use native methods?
The application needs to access drivers for hardware that Java does not know about.
True
False
Question 37 of 61
Given the following code fragment, which of the following lines would be a part of the
output?
outer:
for ( int i = 0 ; i<3 ; i++ )
{
for ( int j = 0 ; j<2 ; j++ )
{
if ( i == j )
{
continue outer;
}
System.out.println( "i=" + i + " , j=" + j );
}
}
i = 1, j = 0
i = 0, j = 1
c
Question 48 of 61
Which of the following statements are true?
A daemon thread is a low priority thread that never stops but keeps running in the back
ground.
Question 49 of 61
What does the zeroth element of the string array passed to the standard main method
contain?
b
a
Question 60 of 61
Which of the following statements are true?
Thread is an interface which has only one method, namely public void run();
Calling the method run( ) on an object castable to Thread will start the new thread.