1. What makes a Thread to stop execution
2. Which is the correct expression to be used to read line by line and store the result into a String object
a) File f = new File("test.txt");
3. Which of the following will not throw a NullPointerException?
String s = null;
4. Which of the following describes a fully encapsulated class?
5. Which state decide a var. ’a’ which is suitable for referring to an array of 50 string objects?
6. In the following program, if somecondition() is true, then only line number 3 must throw a custom exception MyException. MyException is not a subclass of runtime exceptions. What are the changes to be made to the given method.
7. What is the output of the following program
public class Example{
private int i;
public static void main(String args[]) {
method() ;
}
public static void method() {
int j;
j= i;
System.out.println("The value of i is " +i);
}
}
8. Which of the following are true?
Long L9 = new Long(9);
Long L10 = new Long(9);
Long L11 = L10;
long A = 9;
long B = 9;
9. How should we make a class to handle the events generated by a single user interface component?
10. What are the assignments which are valid in the line XXXX
class Super{ private int i; public int ma_cd(float f){ i = (int) f; return i; }} class Sub extends Super{ int j; float g; public Sub(){ Super s = new Super(); XXXX } }
11. What is the output of the above code?
outer : for(int x = 0 ; x<2 ; x++){
inner: for(int a = 0 ; a < 2 ; a++){
if (a==1) {
break inner;
}
System.out.println(" a is " + a + " x is " + x );
}
}
12. Which is the earliest possible instance that Garbage Collection is activated for String created in line 1.
public static void main(String args[ ]){
13. There is a plan to prepare a class which is going to used in many unrelated parts of the project. The class should be Polygon object which is a Shape. The polygon has a information about the coordinates stored in a vector, color status which states whether true or false. Write a class declaration which describes the above
public class Polygon extends Shape{
vector coord;
boolean colorstatus;
}
14. There is an Employee who is a Person. The employee stores details in a Vector, date employed and number of instances. What are the type of
variables that is to be added to the Employee class
15. What is the constructor argument for the FilterInputStream
16. What is the hexadecimal representation of 7 (not more that 4 characters)
0x7
17. What is the output of the following program Example if args[0] is printed
java Example cat dog
18. What is the modifier for all the listener methods
19. Which of the following is true regarding GridBagLayout
20. What is the value of x, if "Test 3" to be printed
Switch(x){
Case 1: System.out.println("Test 1");
Case 2:
Case 3: System.out.println("Test 3"); break;
default : System.out.println("Test 4"); break;
}
21. If the string array name is argc in the arguments in the main method, which is invoked by the interpreter when a program is executed
22. What is the argument of the KeyListener methods
KeyEvent
23. What is the correct declaration of an abstract method
24. How will you override or overload the following method method1 of the Super class in the class Sub?
class Super{
protected void method1() {}
}
class Sub extends Super{}
25. What is the value of x if Test 3 is to be printed
if (x > 4) {
System.out.println( "Test 1" );} else if (x> 9){
System.out.println("Test 2");
} else
System.out.println("Test 3");
26. What is the range of a char type?
0 – 216-1
27. What does >> and >>> denotes
28. What are valid keywords
29. Which of the following should be used to have No Order, Duplication or Perfect retrieval mechanism
30. In which LayoutManager, a component to be added to have only the width resized but not the height
31. What is the access modifier for a class member variable which is to be used in the same package where the class is defined
32. What is the body of a Thread
33. What is the output of the following code?
int i = 0;
do {
System.out.println("The value of i is " + i);
}while(--i > 0)
System.out.println("Finished");
34. What is the output of the following program
class Example{
static int arr[] = new int[10];
public static void main(String args[]){
System.out.println(" The value 4th element is " + arr[4]);
} }
35. Which of the following is the correct class declaration for Car.java. See to that it is a case-sensitive system
int in;
public Car(int inn){
in = inn
} }
int in;
public Car(int inn){
in = inn;
} }
int in;
public abstract void raceCar() {System.out.println("RaceCar");}
public Car(int inn){
in = inn;
} }
public class Car extends Object{
int in;
public Car(int inn){
in = inn;
} }
36. Which of the following are true about Threads?
37. What is true about Garbage Collection mechanism
38. A question on Equality operator
Ok
39. What is the output of the following program?
class Super{
String name;
Super(String s){
name =s ;
} }
class Sub extends Super{
String name;
Sub(String s){
name=s;
}
public static void main(String args[]){
Super sup = new Super("First");
Sub sub = new Sub("Second");
System.out.println(sub.name + " " + sup.name);
}
}
40. An IOException needs to be thrown in some method of a program. Select the correct expression for the raising an exception
41. A Question on Method Overriding
OK
42. What is the output of the following program if method1() does not throw any exception?
try{
method1();
System.out.println("First");
}catch (Exception e){
System.out.prinln("Second");
}finally{
System.out.println("Finally");
} System.out.println("Last");
43. What are the modifier which cannot be used for a local automatic variable
44. What does getID() method of the event return
45. What cannot be added to a container
46. How to invoke the constructor from a constructor in the same class
class Super{
float x;
float y;
float z;
Super(float a, float b){
x = a;
y = b;
}
Super(float a, float b, float c){
XXXX
z = c;
}
}
47. What is true about inner classes?
48. What are the correct declaration for an inner class
49. What are true about Listener interfaces
50. If a class member variable is initialized and the value is not be changed at all, what is the modifier to be used during the declaration of the variable
51. What will happen if the following assignment is made, take the above into account?
class Parent
class Derived1 extends Parent
class Derived2 extends Parent
Parent p;
Derived d1;
p = d1;
52. Which modifiers are to be used to obtain the lock on the object
53. What can be possibly used at Point X
// Point X
public class Example
54. What is the range of int type
-231 to 231-1
55. What is the output of the following program?
class Super{
String firstname;
String secondname;
Super(){}
Super(String f, String s){
firstname = f;
secondname = s;
}
public String toString(){
return "It is Monopoly Mr. " + firstname;
}}
class Sub extends Super{
String firstname;
String secondname;
Sub(String f, String s){
firstname = f;
secondname = s;
}
public String toString(){
return "It is Monopoly Mr. " + secondname + " "+ firstname;
}}
class Test{
public static void main(String args[]){
Super first = new Super("Scott", "McNealy");
Super second = new Sub("Bill","Gates");
System.out.println( second + " \n " +first);
}}
It is Monopoly Mr. Scott
It is Monopoly Mr. McNealy
It is Monopoly Mr. Scott
It is Monopoly Mr. Scott McNealy
56. How to instantiate the class Inner at point XXXX
class Outer{
class Inner{
}
public static void main(String args[]){
XXXX
}
}
57. What is the output of the following program
public class Example{
Stack s1;
Stack s2;
public static void main(String args[]){
new Example();
}
public Example() {
s1 = new Stack();
s2 = new Stack();
method1(s1,s2);
System.out.println(s1 + " " + s2);
}
public void method1(Stack ms1, Stack ms2){
ms2.push(new Long(100));
ms1 = ms2;
}
}
58. What are the legal identifers in Java?
59. Which of the following are true about the listener mathods in AWT? (C)