All Questions


#51Given Answer class behaves like some a File it has a Vector , a color, some boolean variable?

import
public
private
Vector
Serializable
File
Color
extends
boolean
implements

What is the correct declaration?


Answer : -------------------------

#52Some design issues: The following description applies to a class: given someclassname behaves as somesuperclassname and it has some fields etc it is accessed in other files. No other class can behave as this class.
  
extends
public
int
class
someclassname
somesuperclass
implements
File
extends
Class
final

What is the right syntax declaration of this class (without {)?


Answer : -------------------------

#53Which of the following is correct? Select the two correct answers.

(1)The native keyword indicates that the method is implemented in another language like C/C++
(2)The only statements that can appear before an import statement in a Java file are comments
(3)The method definitions inside interfaces are public and abstract. They cannot be private or protected
(4)A class constructor may have public or protected keyword before them, nothing else

Answer : -------------------------

#54What is the result of compiling and running the following program.

public class test {
public static void main(String args[]) {
String str1="abc";
String str2="def";
String str3=str1.concat(str2);

str1.concat(str2);
System.out.println(str1);
}
}




(1)abc
(2)def
(3)abcabc
(4)abcdef
(5)defabc
(6)abcdefdef

Answer : -------------------------

#55What is the result of compiling and running the following program. Select the one correct answer.

class test {
public static void main(String args[]) {
char ch;
String test2 = "abcd";
String test = new String("abcd");
if(test.equals(test2)) {
if(test == test2)
ch = test.charAt(0);
else
ch = test.charAt(1);
}
else {
if(test == test2)
ch = test.charAt(2);
else
ch = test.charAt(3);
}
System.out.println(ch);
}
}


(1)'a'
(2)'b'
(3)'c'
(4)'d'

Answer : -------------------------

#56To make a variable defined in a class accessible only to methods defined in the classes in same package, which of the following keyword should be used. Select the one correct answer

(1)By using the keyword package before the variable
(2)By using the keyword private before the variable
(3)By using the keyword protected before the variable
(4)By using the keyword public before the variable
(5)The variable should not be preceded by any of the above mentioned keywords

Answer : -------------------------

#57Which Listener interface must be implemented by a class responsible for handling mouse clicks on buttons?


Answer : -------------------------

#58Which of the following will output -4.0

(1)System.out.println(Math.floor(-4.7));
(2)System.out.println(Math.round(-4.7));
(3)System.out.println(Math.ceil(-4.7));
(4)System.out.println(Math.Min(-4.7));

Answer : -------------------------

#59What is the result of the following operation?

System.out.println(4 | 3);




(1)6
(2)0
(3)1
(4)7

Answer : -------------------------

#60What will happen when you attempt to compile and run the following code?

class Background implements Runnable {
int i=0;

public int run() {
while(true) {
i++;
System.out.println("i="+i);
}
}
}


(1)It will compile and the run method will print out the increasing value of i
(2)It will compile and calling start will print out the increasing value of i
(3)The code will cause an error at compile time
(4)Compilation will cause an error because while cannot take a parameter of true

Answer : -------------------------

#61What will the following code print out?

public class TechnoSample {
public static void main(String argv[]) {
TechnoSample sample = new TechnoSample();
sample.amethod();
}

public void amethod() {
int oi= 012;
System.out.println(oi);
}
} // Oct

(1)12
(2)012
(3)10
(4)10.0

Answer : -------------------------

#62You need to create a class that will store a unique object elements. You do not need to sort these elements but they must be unique.

What interface might be most suitable to meet this need?

(1)Set
(2)List
(3)Map
(4)Vector

Answer : -------------------------

#63You are concerned about that your program may attempt to use more memory than is available. To avoid this situation you want to ensure that the Java Virtual Machine will run its garbage collection just before you start a complex routine. What can you do to be certain that garbage collection will run when you want.

(1)You cannot be certain when garbage collection will run
(2)Use the Runtime.gc() method to force garbage collection
(3)Ensure that all the variables you require to be garbage collected are set to null
(4)Use the System.gc() method to force garbage collection

Answer : -------------------------

#64Which of the following most closely describes a bitset collection?

(1)A class that contains groups of unique sequences of bits
(2)A method for flipping individual bits in instance of a primitive type
(3)An array of boolean primitives that indicate zeros or ones
(4)A collection for storing bits as on-off information, like a vector of bits

Answer : -------------------------

#65You have these files in the same directory. What will happen when you attempt to compile and run Class1.java if you have not already compiled Base.java

//Base.java
package Base;

class Base {
protected void amethod() {
System.out.println("amethod");
}
} // Base

package Class1;

public class Class1 extends Base {
public static void main(String argv[]) {
Base b = new Base();
b.amethod();
}
} // Class1

(1)Compile Error: Methods in Base not found
(2)Compile Error: Unable to access protected method in base class
(3)Compilation followed by the output "amethod"
(4)Compile error: Superclass Class1.Base of class Class1.Class1 not found

Answer : -------------------------

#66Given:

class TechnoSample {
public static void main(String args[]) {
short[] s = {1, -1, 3, 4};
for (int i = 0; i switch(s[i]) {
case 2-1: System.out.print("v ");
break;
case 'd'-'a': System.out.print("w ");
break;
case 0: System.out.print("x ");
break;
case ~0: System.out.print("y ");
break;
case 4&5: System.out.print("z ");
break;
default: System.out.print("Default ");
}
}
}
}

What is the result of attempting to compile and run the above program?

(1)Prints: v w x y
(2)Prints: v w x y z Default
(3)Prints: v y w z
(4)Prints: Default Default Default Default
(5)Runtime Exception
(6)Compiler Error
(7)None of the Above

Answer : -------------------------

#67Given:

class TechnoSample {
public static void main (String args[]) {
int i = 0;
int j = 0;
label1:
while (i++<5) {
label2:
for (;;) {
label3:
do {
System.out.print(i + j);
switch (i+j++) {
case 0: continue label3;
case 1: continue label2;
case 2: continue label1;
case 3: break;
case 4: break label3;
case 5: break label2;
case 6: break label1;
default: break label1;
}
} while (++j<5);
}
}
}
}

What is the result of attempting to compile and run the above program?

(1)Prints: 12457
(2)Prints: 02357
(3)Prints: 02356
(4)Prints: 1357
(5)Prints: 1356
(6)Runtime Exception
(7)Compiler Error
(8)None of the Above

Answer : -------------------------

#68

1. class A {
2. void m1() {throw new ArithmeticException();}
3. void m2() {throw new ClassCastException();}
4. void m3() {throw new IllegalArgumentException();}
5. void m4() {throw new IndexOutOfBoundsException();}
6. void m5() {throw new NullPointerException();}
7. void m6() {throw new SecurityException();}
8. }

What is the result of attempting to compile the program?

(1)Compiler error at line 2
(2)Compiler error at line 3
(3)Compiler error at line 4
(4)Compiler error at line 5
(5)Compiler error at line 6
(6)Compiler error at line 7
(7)None of the Above

Answer : -------------------------

#69

class Level1Exception extends Exception {}
class Level2Exception extends Level1Exception {}
class Level3Exception extends Level2Exception {}

class Purple {
public static void main(String args[]) {
int a,b,c,d,f,g,x;
a = b = c = d = f = g = 0;
x = 3;
try {
try {
switch (x) {
case 1: throw new Level1Exception();
case 2: throw new Level2Exception();
case 3: throw new Level3Exception();
}
a++;
}
catch (Level2Exception e) {b++;}
finally{c++;}
}
catch (Level1Exception e) { d++;}
catch (Exception e) {f++;}
finally {g++;}
System.out.print(a+","+b+","+c+","+d+","+f+","+g);
}
}

What is the result of attempting to compile and run the program?

(1)Prints: 1,1,1,0,0,1
(2)Prints: 0,1,1,0,0,1
(3)Prints: 0,1,0,0,0,0
(4)Prints: 0,1,0,0,0,1
(5)Prints: 0,0,1,0,0,1
(6)Compiler Error
(7)Run Time Error
(8)None of the Above

Answer : -------------------------

#70

class A {

public static void main (String args[]) {
int h = 0, i = 0, j = 0, k = 0;

label1:
for (;;) {
h++;

label2:
do {
i++;
k = h + i + j;

switch (k) {
default: break label1;
case 1: continue label1;
case 2: break;
case 3: break label2;
case 4: continue label2;
case 5: continue label1;
}
} while (++j<5);
}
System.out.println(h + "," + i + "," + j);
}
}

What is the result of attempting to compile and run the above program?

(1)Prints: 1,2,3
(2)Prints: 1,3,2
(3)Prints: 2,2,2
(4)Prints: 2,4,1
(5)Prints: 2,4,2
(6)Runtime Exception
(7)Compiler Error
(8)None of the Above

Answer : -------------------------

#71Which of the follow are true statements.

(1)A nested class is any class that is declared within the body of another class or interface
(2)A nested class can not be declared within the body of an interface declaration
(3)A top level class is a class this is not a nested class
(4)An inner class is a nested class that is not static
(5)A nested class can not be declared static
(6)A named class is any class that is not anonymous
(7)None of the above

Answer : -------------------------

#72The only access control modifiers supported by Java are:

public
protected
private


(1)True
(2)False

Answer : -------------------------

#73Which of the following are True?

(1)() is a unary operator
(2)() is a function operator
(3)int x = 10 + +11; is a invalid statment
(4)int x = (char)(int)(10); will give compiler error

Answer : -------------------------

#74Which of the following statements are False?

(1)Checked exceptions can not be caught using catch() in the same function
(2)New exception can be thrown with in a catch block
(3)No exception can be thrown from a finally block
(4)for loop executes its block statments atleast once
(5)Unhandled exceptions are handled by JVM and the program will coninue

Answer : -------------------------

#75What will happen if you compile/run this code?

1: public class Q1 extends Thread
2: {
3: public void run()
4: {
5: System.out.println("Before start method");
6: this.stop();
7: System.out.println("After stop method");
8: }
9:
10: public static void main(String[] args)
11: {
12: Q1 a = new Q1();
13: a.start();
14: }
15: }


(1)Compilation error at line 7
(2)Runtime exception at line 7
(3)Prints "Before start method" and "After stop method"
(4)Prints "Before start method" only

Answer : -------------------------

#76The following code will give:

1 class Test
2 {
3 void show()
4 {
5 System.out.println("non-static method in Test");
6 }
7 }
8 public class Q3 extends Test
9 {
10 static void show()
11 {
12 System.out.println("Overridden non-static method in Q3");
13 }
14
15 public static void main(String[] args)
16 {
17 Q3 a = new Q3();
18 }
19 }


(1)Compilation error at line 3
(2)Compilation error at line 10
(3)No compilation error, but runtime exception at line 3
(4)No compilation error, but runtime exception at line 10

Answer : -------------------------

#77The following code will print:

1 if( new Boolean("true") == new Boolean("true"))
2 System.out.println("True");
3 else
4 System.out.println("False");


(1)Compilation error
(2)No compilation error, but runtime exception
(3)Prints "True"
(4)Prints "False"

Answer : -------------------------

#78Which of the following statements are True?

(1)Constructors cannot have a visibility modifier
(2)Constructors can be marked public and protected, but not private
(3)Constructors can only have a primitive return type
(4)Constructors are not inherited

Answer : -------------------------

#79Which of the following will compile without error?

(1)char c='1';
System.out.println(c>>1);
(2)Integer i=Integer("1");
System.out.println(i>>1);
(3)int i=1;
System.out.println(i<<<1);
(4)int i=1;
System.out.println(i<<1);

Answer : -------------------------

#80You are given a class hierarchy with an instance of the class Dog. The class Dog is a child of mammal and the class Mammal is a child of the class Vertebrate. The class Vertebrate has a method called move which prints out the string "move". The class mammal overrides this method and prints out the string "walks". The class Dog overrides this method and prints out the string "walks on paws". Given an instance of the class Dog,. how can you access the ancestor method move in Vertebrate so it prints out the string "move";

(1)d.super().super().move();
(2)d.parent().parent().move();
(3)d.move();
(4)none of the above

Answer : -------------------------

#81Which of the following statements are True?

(1)An inner class may be defined as static
(2)There are NO circumstances where an inner class may be defined as private
(3)A programmer may only provide one constructor for an anonymous class
(4)An inner class may extend another class

Answer : -------------------------

#82Under what circumstances might you use the yield method of the Thread class

(1)To call from the currently running thread to allow another thread of the same or higher priority to run
(2)To call on a waiting thread to allow it to run
(3)To allow a thread of higher priority to run
(4)To call from the currently running thread with a parameter designating which thread should be allowed to run

Answer : -------------------------

#83What will be the result when you attempt to compile this program?

public class Rand {
public static void main(String argv[]) {
int iRand;
iRand = Math.random();
System.out.println(iRand);
}
} // Rand

(1)Compile time error referring to a cast problem
(2)A random number between 1 and 10
(3)A random number between 0 and 1
(4)A compile time error about random being an unrecognised method

Answer : -------------------------

#84It is possible for two classes to be the super class of each other. True Or False?

(1)True
(2)False

Answer : -------------------------

#85Given classes A, B & C where B extends A and C extends B, and where all classes implement the instance method 'void print()'. How can the print() method in A be called from an instance method in C?

Select one right answer.

(1)print();
(2)super.print();
(3)super.super.print();
(4)this.super.print();
(5)A.this.print();
(6)((A)this).print();
(7)It is not possible

Answer : -------------------------

#86Which of these statements are valid when occuring by themselves?

Select all valid answers.

(1)while() break;
(2)do { break; } while (true);
(3)if (true) { break; }
(4)switch (1) { default: break; }
(5)for (;true;) break;

Answer : -------------------------

#87All public methods in the Thread class are static and therefore only affect the current thread. True Or False?

(1)True
(2)False

Answer : -------------------------

#88Which of the following statements regarding threads are true?

Select all valid statements.

(1)void run(void) method is one of the methods in the Runnable interface
(2)yield() causes the current thread to move into the ready state
(3)some of the public methods in the Thread class are static
(4)notify() takes one argument, the object to which it needs to notify and notifyAll() takes no arguments
(5)every object has a lock which controls which thread has access to the objects synchronized code
(6)wait, notify & notifyAll methods must always be called from inside synchronized code
(7)wait, notify & notifyAll methods are part of Thread class only

Answer : -------------------------

#89The following code will print:

1: Double a = new Double(Double.NaN);
2: Double b = new Double(Double.NaN);
3:
4: if( Double.NaN == Double.NaN )
5: System.out.println("True");
6: else
7: System.out.println("False");
8:
9: if( a.equals(b) )
10: System.out.println("True");
11: else
12: System.out.println("False");


(1)True
True
(2)True
False
(3)False
True
(4)False
False

Answer : -------------------------

#90What will happen if you compile/run the following code?

1 public class Q11
2 {
3 static String str1 = "main method with String[] args";
4 static String str2 = "main method with int[] args";
5
6 public static void main(String[] args)
7 {
8 System.out.println(str1);
9 }
10
11 public static void main(int[] args)
12 {
13 System.out.println(str2);
14 }
15 }


(1)Duplicate method main(), compilation error at line 6
(2)Duplicate method main(), compilation error at line 11
(3)Prints "main method with main String[] args"
(4)Prints "main method with main int[] args"

Answer : -------------------------

#91What is the output of the following code?

1 int i = 16;
2 int j = 17;
3
4 System.out.println("i >> 1 = " + (i >> 1));
5 System.out.println("j >> 1 = " + (j >> 1));


(1)Prints i >> 1 = 8
j >> 1 = 8
(2)Prints i >> 1 = 7
j >> 1 = 7
(3)Prints i >> 1 = 8
j >> 1 = 9
(4)Prints i >> 1 = 7
j >> 1 = 8

Answer : -------------------------

#92What is the output of the following code?

1 int i = 45678;
2 int j = ~i;
3
4 System.out.println(j);



(1)Compilation error at line 2. ~ operator applicable to boolean values only
(2)Prints 45677
(3)Prints -45677
(4)Prints -45679

Answer : -------------------------

#93What will happen when you invoke the following method?

1 void infiniteLoop()
2 {
3 byte b = 1;
4
5 while ( ++b > 0 )
6 ;
7 System.out.println("Welcome to Java");
8 }



(1)The loop never ends(infiniteLoop)
(2)Prints "Welcome to Java"
(3)Compilation error at line 5. ++ operator should not be used for byte type variables
(4)Prints nothing

Answer : -------------------------

#94Which of the following are syntactically correct?

(1)String[] sa1,sa2;
(2)Integer iwSize[] = new Integer[]{new Integer(1)};
(3)short s[] = new short[10];
(4)int i[10];

Answer : -------------------------

#95Given the following code, which statement is true?

class A {}
class B extends A {}

public class C
{
public static void main(String[] args)
{
A[] arrA;
B[] arrB;

arrA = new A[10];
arrB = new B[20];

arrA = arrB; // (1)
arrB = (B[]) arrA; // (2)

arrA = new A[10];
arrB = (B[]) arrA; // (3)
}
}

Select one right answer.

(1)The code will fail to compile owing to the line labeled (1)
(2)The code will throw a java.lang.ClassCastException at the line labelel (2), when run
(3)The code will throw a java.lang.ClassCastException at the line labelel (3), when run
(4)The code will compile and run without problems, even if the (B[]) cast in the lines labeled (2) & (3) were removed
(5)The code will compile and run without problems, but would not do so if the (B[]) cast in the lines (2) & (3) were removed

Answer : -------------------------

#96Given the following code

public class Boxes{
String sValue;

Boxes(String sValue){
this.sValue=sValue;
}

public String getValue(){
return sValue;
}

public boolean equals(Object o){
String s = (String) o;
if (sValue.equals(s) ){
return true;
}else{
return false;
}


}

public int hashCode(){
return sValue.hashCode();

}
}

Which of the following statements are true?

(1)The hashCode method is correctly implemented
(2)This class will not compile as String has no hashCode method
(3)The hashCode method is not icorrectly implemented
(4)This class will not compile because the compareTo method is not implemented

Answer : -------------------------

#97Which of the following are methods of the Collection interface?

(1)iterator
(2)isEmpty
(3)toArray
(4)setText

Answer : -------------------------

#98What can cause a thread to stop executing?

(1)The program exits via a call to System.exit(0);
(2)Another thread is given a higher priority
(3)A call to the thread's stop method
(4)A call to the halt method of the Thread class

Answer : -------------------------

#99Given:

public class TechnoExample
{
int xyz = 22;
...

public void static main(String junkArgs[])
{
...
}
}

While one of the following statements is true? Select one correct answer.

(1)this.xyz is accessible from the main method with any access specifier for xyz
(2)this.xyz is accessible from the main method if the declaration of xyz is private
(3)this.xyz is accessible from the main method if the declaration of xyz is public
(4)This.xyz is accessible from the main method without any changes to the existing code

Answer : -------------------------

#100Which of the following statements are true?

(1)Creating a Thread using the Runnable interface does not require direct access to the Thread class
(2)Using the Thread class does not require any additional import statements
(3)yield is a static method of the Thread class
(4)yield is a static method of the Object class

Answer : -------------------------


2001-2003 Technopark. Developed by: Giri Mandalika