30
Question 1 of 61 In the following code what will be the output if 0 (integer value zero) is passed to loopTest()? (See Exhib it) 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); } } } } Select 1 correct option. a The prog ram will not compile.   b It will print 1 2 3 4.  c It will print 1 1 2 3 4  d It will print 1 1 2 2 3 3 4 4  e Produces no output Question 2 of 61 Which line contains a valid constructor in the following class definition?

Output 222

Embed Size (px)

Citation preview

Page 1: Output 222

8/8/2019 Output 222

http://slidepdf.com/reader/full/output-222 1/30

Question 1 of 61

In the following code what will be the output if 0 (integer value zero) is passed toloopTest()?(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);

}}

}

}

Select 1 correct option.a

The program will not compile.

b

It will print 1 2 3 4.

c

It will print 1 1 2 3 4

d

It will print 1 1 2 2 3 3 4 4

e

Produces no output

Question 2 of 61

Which line contains a valid constructor in the following class definition?

Page 2: Output 222

8/8/2019 Output 222

http://slidepdf.com/reader/full/output-222 2/30

Question 12 of 61

Given the following class, which statements can be inserted at line 1 without causing thecode to fail compilation?

public class TestClass{

int a;int b = 0;static int c;public void m(){

int d;int e = 0;// Line 1

}}

Select 4 correct optionsa

a++;

b

b++;

c

c++;

d

d++;

e

e++;

Question 13 of 61

Which lines contain a valid constructor in the following code?public class TestClass

Page 3: Output 222

8/8/2019 Output 222

http://slidepdf.com/reader/full/output-222 3/30

Select 1 correct option.a

javajava

b

lavajava

c

javajavac

d

lavajavac

e

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)

Page 4: Output 222

8/8/2019 Output 222

http://slidepdf.com/reader/full/output-222 4/30

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");}}

Select 1 correct option.a

The program will fail to compile.

b

It will always print 'String1' 'String2' and 'end', in that order.

c

It will always print 'String1' 'String2' in random order followed by 'end'.

d

It will always print 'end' first.

e

No order is guaranteed.

Page 5: Output 222

8/8/2019 Output 222

http://slidepdf.com/reader/full/output-222 5/30

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 isblocked.What will allow the thread T2 to become runnable?

Select 1 correct option.a

Thread T1 calls Thread.sleep(100).

b

Thread T2's wait() times out.

c

Thread T1 is interrupted.

d

Thread T1 releases the lock on Obj and calls the notify() method on T2.

e

Thread T1 releases the lock on Obj and calls the notify() method on Obj.

Question 45 of 61

Page 6: Output 222

8/8/2019 Output 222

http://slidepdf.com/reader/full/output-222 6/30

a

instance { bool = true; }

b

InitTest() { si += 10; }

c

{ si = 5; i = bool ? 1000 : 2000;}

d

{ i = 1000; }

e

{ bool = (si > 5); 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?

Select 2 correct optionsa

o1.equals(o2) is always false.

b

o1.hashCode( ) == o2.hashCode( ) is always false.

c

o1 == o2 is always false.

Page 7: Output 222

8/8/2019 Output 222

http://slidepdf.com/reader/full/output-222 7/30

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");}

Select 1 correct option.a

Compile time error.

b

It will print true.

c

It will print false.

d

Runtime error.

e

It will print nothing.

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)

Page 8: Output 222

8/8/2019 Output 222

http://slidepdf.com/reader/full/output-222 8/30

Question 13 of 61

Which of the following statements are true?

Select 2 correct optionsa

An inner class may be declared static

b

Anonymous inner class may be declared public.

c

Anonymous inner class may be declared private.

d

Anonymous inner class may be declared protected.

e

Anonymous inner class may extend an abstract class.

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;

Page 9: Output 222

8/8/2019 Output 222

http://slidepdf.com/reader/full/output-222 9/30

Question 25 of 61

Which of the following methods are available in the java.lang.Math class?

Select 4 correct optionsa

double IEEEremainder(double, double)

b

double log(double a)

c

double log10(double a)

d

double rint(double a)

e

float max(float, float)

Question 26 of 61

Which of the following are valid declarations of the standard main() method?

Select 2 correct optionsa

static void main(String args[ ]) { }

b

public static int main(String args[ ]) {}

Page 10: Output 222

8/8/2019 Output 222

http://slidepdf.com/reader/full/output-222 10/30

Question 37 of 61

What will be the result of attempting to compile this class?

package test;

public class TopClass{

public Inner inner1;}class Inner{

int value;}

Select 1 correct option.

a

The class will fail to compile, since the class Inner has not yet been declared whenreferenced in class TopClass.

b

The class will fail to compile, since inner is a keyword.

c

The class will fail to compile, since you cannot write 2 classes in the same file.

d

The class will fail to compile, since the class Inner must be defined in a file calledInner.java

e

The classes will compile.

Question 38 of 61

Expression ( s instanceof java.awt.Point ) will return false if 's' was declared as avariable of class java.lang.String.

Page 11: Output 222

8/8/2019 Output 222

http://slidepdf.com/reader/full/output-222 11/30

a

True

b

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) ;}

}

Select 2 correct optionsa

A

b

B

c

C

d

Page 12: Output 222

8/8/2019 Output 222

http://slidepdf.com/reader/full/output-222 12/30

Select 2 correct optionsa

a

b

b

c

c

d

d

e

e

Question 61 of 61

Which of the following statements is correct?

Select 1 correct option.a

new, delete and goto are keywords in the Java language

b

try, catch and thrown are keywords in the Java language

c

static, unsigned and long are keywords in the Java language

Page 13: Output 222

8/8/2019 Output 222

http://slidepdf.com/reader/full/output-222 13/30

Question 1 of 61

Which statements concerning the following code are true?

class A{

public A() {} // A1public A(String s) { this(); System.out.println("A :"+s); } // A2}class B extends A{

public int B(String s) { System.out.println("B :"+s); return 0; }// B1}class C extends B{

private C(){ super(); } // C1public C(String s){ this(); System.out.println("C :"+s); } // C2public C(int i){} // C3

}

Select 4 correct optionsa

One of the constructors of each class is called as a result of constructing an object of classC.

b

Constructor // A2 will never be called in creation of an object of class C

c

Class C can be instanciated only in two ways by users of this class.

d

// B1 will never be called in creation of objects if class A B or C

e

The code will not compile.

Question 2 of 61

Page 14: Output 222

8/8/2019 Output 222

http://slidepdf.com/reader/full/output-222 14/30

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++) ); //1bool = ( bool2 && method1(i++) ); //2bool = ( bool1 | method1(i++) ); //3bool = ( bool1 || method1(i++) ); //4System.out.println(i);

}public static boolean method1(int i){

return i>0 ? true : false;}

}

Select 1 correct option.a

It will print 1.

b

It will print 2.

c

It will print 3.

d

It will print 4.

e

It will print 0.

Page 15: Output 222

8/8/2019 Output 222

http://slidepdf.com/reader/full/output-222 15/30

Question 25 of 61

Empty file is a valid source file.

Select 1 correct option.a

True

b

False

Question 26 of 61

Which of the following are true about the "default" constructor?

Select 2 correct optionsa

It is provided by the compiler only if the class does not define any constructor.

b

It initializes the instance members of the class.

c

It calls the default 'no-args' constructor of the super class.

d

It initializes instance as well as class fields of the class.

e

' '

Page 16: Output 222

8/8/2019 Output 222

http://slidepdf.com/reader/full/output-222 16/30

a

Using the setPriority( ) method in the class Thread.

b

Give the priority as a parameter to the constructor of the thread.

c

A thread can have priority from 1 to 10.

d

Thread Priorities are given by the OS.

e

None of the above.

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?

Select 4 correct optionsa

Page 17: Output 222

8/8/2019 Output 222

http://slidepdf.com/reader/full/output-222 17/30

Select 1 correct option.a

It will not compile.

b

It will throw ArrayIndexOutOfBoundsException when run.

c

It will print 1.

d

It will print 3.

e

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);

Select 1 correct option.a

True

b

False

Page 18: Output 222

8/8/2019 Output 222

http://slidepdf.com/reader/full/output-222 18/30

Question 60 of 61

Which of the following classes extend the java.lang.Number class?

Select 4 correct optionsa

java.lang.Integer

b

java.lang.Byte

c

java.lang.Character

d

java.lang.Double

e

java.lang.Short

Question 61 of 61

Which of the following is not a legal Java identifier?

Select 1 correct option.a

num

b

int123

Page 19: Output 222

8/8/2019 Output 222

http://slidepdf.com/reader/full/output-222 19/30

Question 1 of 61

Which of the following correctly declare a variable which can hold an array of 10 integers?

Select 2 correct optionsa

int[ ] iA

b

int[10] iA

c

int iA[ ]

d

Object[ ] iA

e

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 + " "); //1for (int i = 10; i > 0; i--) System.out.print(i + " "); //2int i = 20; //3System.out.print(i + " "); //4

}}

Which of the following statements are true?

Page 20: Output 222

8/8/2019 Output 222

http://slidepdf.com/reader/full/output-222 20/30

Select 1 correct option.a

It will print 'equal'.

b

It will print 'not equal'.

c

Compile time error at //1

d

Runtime error at //1

e

None of the above.

Question 12 of 61

Which of the following are correct ways to initialize the static variables MAX andCLASS_GUID ?

class Widget{

static int MAX; //1static final String CLASS_GUID; // 2Widget()

{ //3}Widget(int k){

//4}

}

Select 2 correct options

a

Page 21: Output 222

8/8/2019 Output 222

http://slidepdf.com/reader/full/output-222 21/30

Question 22 of 61

Which two of the following statements are equivalent?

Select 2 correct optionsa

3*2^2

b

3<2

c

3<<2

d

3<<<2

e

3*4

Question 23 of 61

Which of the following statements are true?

Select 1 correct option.a

For any non-null reference o1, the expression (o1 instanceof o1) will always yield true.

b

For any non-null reference o1, the expression (o1 instanceof Object) will always yield

Page 22: Output 222

8/8/2019 Output 222

http://slidepdf.com/reader/full/output-222 22/30

Question 34 of 61

Which of the following statements are true?

Select 3 correct optionsa

Interface Runnable is just a tag interface and has no methods.

b

Interface Runnable has one method.

c

class Thread implements Runnable.

d

All objects castable to Thread are castable to Runnable.

e

All objects castable to Runnable are castable to Thread.

Question 35 of 61

What is the name of the method that threads can use to pause their execution untilsignalled by another thread to continue ?(Do not include a parameter list or brackets or semicolon.)

Page 23: Output 222

8/8/2019 Output 222

http://slidepdf.com/reader/full/output-222 23/30

Select 1 correct option.a

1, 3

b

4, 5

c

2, 3

d

1, 2, 3

e

2

Question 46 of 61

Consider the following code that uses an assertion to ensure that the program is suppliedwith 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?

Select 1 correct option.a

This is an appropriate use of assertions.

b

Page 24: Output 222

8/8/2019 Output 222

http://slidepdf.com/reader/full/output-222 24/30

Question 57 of 61

Which interfaces does java.util.Hashtable implement?

Select 1 correct option.a

java.util.SortedSet

b

java.util.Map

c

java.util.SortedMap

d

java.util.TreeMap

e

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?

Select 2 correct options

Page 25: Output 222

8/8/2019 Output 222

http://slidepdf.com/reader/full/output-222 25/30

Question 1 of 61

What will be the result of attempting to compile the following program?

public class TestClass{

long l1;public void TestClass(long pLong) {l1 = pLong ; } //(1)public static void main(String args[]){

TestClass a, b ;a = new TestClass(); //(2)b = new TestClass(5); //(3)

}}

Select 1 correct option.a

A compilation error will be encountered at (1), since constructors should not specify areturn value.

b

A compilation error will be encountered at (2), since the class does not have a defaultconstructor.

c

A compilation error will be encountered at (3).

d

The program will compile correctly.

e

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

Page 26: Output 222

8/8/2019 Output 222

http://slidepdf.com/reader/full/output-222 26/30

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

}}

Select 1 correct option.a

b = b1;

b

b2 = b;

c

b1 = (B1) b;

d

b2 = (B2) b1;

e

b1 = (B) b1;

Question 14 of 61

Which statments about the output of the following programs are true?

Page 27: Output 222

8/8/2019 Output 222

http://slidepdf.com/reader/full/output-222 27/30

Select 1 correct option.a

Compilation error.

b

It will print 'Equal'.

c

It will print 'Not Equal'.

d

Runtime error.

e

None of the above.

Question 25 of 61

What application requirements may need you to use native methods?

Select 3 correct optionsa

The application needs to do computation intensive job.

b

The application needs to access drivers for hardware that Java does not know about.

c

The application needs to make fields of a class globally available.

Page 28: Output 222

8/8/2019 Output 222

http://slidepdf.com/reader/full/output-222 28/30

Question 36 of 61

If a synchronized method throws an exception in it's execution, the lock accquired by it isreleased automatically.

Select 1 correct option.a

True

b

False

Question 37 of 61

Given the following code fragment, which of the following lines would be a part of theoutput?

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 );

}}

Select 2 correct optionsa

i = 1, j = 0

b

i = 0, j = 1

c

Page 29: Output 222

8/8/2019 Output 222

http://slidepdf.com/reader/full/output-222 29/30

Question 48 of 61

Which of the following statements are true?

Select 1 correct option.a

A program ends when all daemon threads end.

b

A program ends when all non-daemon threads end.

c

A program ends when all threads end.

d

A daemon thread is a low priority thread that never stops but keeps running in the back ground.

e

A user thread cannot stop a non-user or daemon thread.

Question 49 of 61

What does the zeroth element of the string array passed to the standard main methodcontain?

Select 1 correct option.a

The name of the class.

b

Page 30: Output 222

8/8/2019 Output 222

http://slidepdf.com/reader/full/output-222 30/30

a

a

b

b

c

c

d

d

Question 60 of 61

Which of the following statements are true?

Select 1 correct option.a

The class Thread does not implement Runnable.

b

The class Thread is abstract.

c

Thread is an interface which has only one method, namely public void run();

d