
SCJP QUESTIONS
1) Which are valid java identifiers?
a. employee
b. thisemployee
c. %employee
d. $employee
Ans :: a,b,d
2) What is range of int
Ans :: -2^31 to 2^31 - 1
3) parent
/ \
/ \
der1 der2
parent p=new parent();
der1 d = new der1();
p = d;
Is above assignment valid during
1.only compilation
2.only run
3.both
Ans :: 3
4) Float f1 = new Float(0.9f);
Double d1 = new Double(0.9);
float f = 0.9f;
double d = 0.9;
Which of following will return true?
1. f1 == d1 //compile-time error
2. f1.equals(new Float(0.9))
3. f ==f1 //compile-time error
4. f==d
5. d1==d
Ans :: 2

5) public static void main(String [] args){
Stack s1 = new Stack();
Stack s2 = new Stack();
amethod(s1, s2);
System.out.println("s1 is" + s1 + " s2 is " + s2);
}
public static void amethod(Stack s1, Stack s2){
s2.push(100);
s1 = s2;
}
What will be the output if I compile and run the program
1. s2 will have 100
s1 will be empty
and some more options.
Ans :: 1.
6)Which of the following are valid keywords in Java?
a. NULL
b. sizeof
c. extends
d. implement
e. instanceof
Ans :: c,e
7) What is range of char
Ans :: 0 to 2^16 – 1
8).
public class Test //(fill in the blanks)
{
int i;
int j;
float f;
Test(int a, int b)
{

//some complex processing and variable initiakization of i ans j
}
Test(int a, int b, float c)
{
//complex processing same as above and variable initialization for i and j
f = c;
}
}
What is the shortest way to do the required processing and initialization that can replace
the commented portion in the second constructor. Don't type any spaces in your response.
Ans :: this(a,b);
9) The class Polygon is Shape. It contains a Vector of points, a Color and a boolean
flag for the fill value.
Write the initial declaration of the signature of the Polygon class from the
following pool of words and spaces only.
Polygon Object public class Vector Color boolean
Fill in the blanks.
(Please check what "class signature" could mean, because I wrote
pulbic class Polygon extends Shape {Vector v; Color c; boolean b}
and I think I got it wrong).
Ans :: public class Polygon extends Shape
10) This program is written in a file called Car.java on a case sensitive platform.
Which of the following declarations are correct.
a. public class Car{
int price;
}
b. public class Car extends A, B{
int price;
}
c. protected class Car{
int price;
}
d. public class Car extends Object{

int x;
}
Ans :: a,d
11) outer: (C)
for (int i = 1; i < 2; i++){
inner:
for (int j = 1; j < 2; j++){
if (i == j)
continue outer;
}
System.out.println(i + " " + j);
}
What will be there in the output.
Ans :: Nothing….
12) int i = 0;
do{
System.out.println(i);
}while(--i > 0)
System.out.println("finished");
What will be printed in the output.
Ans :: 0
finished
13) The object created at line no. 2 is available for garbage collection at which point.
1. public static void main(String [] args){
2. String s1 = new String("one");
3. String s2 = new String("two");
4. System.out.println(s1);
5. System.out.println(s2);
6. s1 = null;
7. s1 = s2;
8. System.out.println(s1);
9. System.out.println(s2);
10. s1 = null;
11. }

Ans :: After Line No. 6
14) Which of the following is true about garbage collection
a) In Multi threaded applications, each thread should have special pieces of code
to handle garbage collection
b) garbage collection is predictable
c) user has control over garbage collection
d) user has control over specifying that object referenced through a reference
won't be used in future.
e). Garbage collector does not collect object which r accessed by any thread of the
running application
Ans :: d,e
15) A Thread stops executing when
a) An InterruptedException is thrown
b) It calls wait()
c) The thread is trying to read from some input source
d) The thread's stop() is called
e) The thread comes out of its run() method
f) When it calls waitForThread();
g). when it calls waitForImage();
Ans :: b,c,d,e,f,g
16) Which of these classes in java.util support unordered elements,does not allow
duplication and which has no keys for retrival
a) Collection
b) Set
c) Enumeration
d) List
e) Map
Ans :: b
17) How to create a button whose width is that of the enclosing frame (container)
and whose height is respected.
a) use FlowLayout
b) use BorderLayout and add the button in East or West
c) use BorderLayout and add the button in North or South
d) use GridLayout one row and two columns
评论2