Java Certification Model Question & Answer
- 1
- What of the following will stop the execution of a running Thread ?
- When the thread throws an interrupted exception.
- When a high priority thread starts running.
- While the thread’s wait method is called.
- When the main method completes.
- In the running thread when a new thread is created
Which of the following will throw a NullPointerException?
String s = null;
- if ((s!=null) & (s.length() > 0))
- if ((s!=null) && (s.length() == 0))
- if ((s==null) | (s.length() > 0))
- if ((s==null) || (s.length() > 0))
Which of the following describes a fully encapsulated class?
Methods cannot be private
Variables cannot be private
All instance variables are private.
All instance variables are public
All instance variables are private and public accessor methods are
provided to get the values of instance variables
In the following program, if somecondition() returns 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 to handle the eception
Class Exceptionthrown{
public void method() {
--------------
---------------
If (somecondition()) {
}
}
}
- Add throws new MyException(); in line number 4
- Add throw MyException(); in line number 6
- Add throw new MyException(); in line number 6
- Add throw new MyException(); in line number 4
- Modify the method declaration such that an object of type Exception is
to be thrown
What is the output of the following program
public class Trial{
int x;
public static void main(String args[]) {
x = 8;
System.out.print("The value of x is " + x);
} }
The program prints The value of x is 8;
The program prints The value of x is 0;
The program will not compile.
Given the following code
Float F1 = new Float(0.9F);
Float F2 = new Float(0.9F);
Double D1 = new Double (0.9);
Which of the following will return true?
- (F1 == F2)
- (F1 == D2)
- F1.equals(F2)
- F1.equals(D2)
- F1.equals(new Float(0.9F))
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
}
}
j = i;
g = f;
j = s.ma_cd(3.2f);
j = s.i;
g = s.f;
Which is the earliest possible instance at which the String object
referred by s is eligible for Garbage Collection?
public static void main(String args[ ]){
- String s = "abcd";
- String s1 = "efghi";
- String s2 = s+ s1;
- s = null;
- s = s1;
- s1 = s;
- Before Line 4.
- Before Line 5 starts
- After Line 5.
- Before line 6.
A Polygon is drawable. You want to store the coordinates of the Polygon in
a vector. The Polygon has color and fill flags. Which of the following types
will you choose for declaring the variables of a Polygon class.
Vector
drawable
Polygon
Color
Boolean
An Employee is a Person. The Employee has a identity, name etc. There is a
plan to prepare a class of type Employee which is going to used in many
unrelated parts of the project. Using the following keywords construct a class
that defines an Employee.
abstract, public, Employee, throws, class, Person, void,
extends
public class Employee extends Person
FilterOutputStream has sub classes such as BufferedOutputStream,
DataOutputStream and PrintStream. Which of the following is the valid argument
type for the constructor of the FilterOutputStream
File
PrintStream
DataOutputStream
BufferedOutputstream
FileOutputStream
What is the equivalent Octal representation of 7 (not more that 4
characters)
07
What is the return type of the methods in Java 2 Listener Interfaces ?
Boolean
boolean
void
String
int
Which of the following is true regarding GridBagLayout
if a component has been given fill both is true, then as the container
resizes the component resizes
The number of rows and columns are fixed while loading the components.
The number of rows and columns are fixed while loading the layout itself
.
if a component has a non-zero weightY value, then the component grows in
height as the container is resized.
Given the following code
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;
}
What are the possible values of x if "Test 3" is to be
printed ?
4
2
3
1
0
What is the valid argument type for the methods in a MouseMotionListener
Interface ?
MouseEvent
Which of the following is valid native method declaration in Java ?
public static void native method1(){}
static void native method1(){}
static native void method1();
static void native method1(){}
static native int method1();
Given the following code
class Super{
public void method1() {}
}
class Sub extends Super{
// xx
}
Which of the following methods can be legally added at line
marked xx ?
int method1() { }
String method1() throws IOException{ }
void method1(String s) { }
void method1(Float s) { }
public void method2() { }
Given the following code
if (x > 4) {
System.out.println( "Test 1" );
}
else if (x> 9){
System.out.println("Test 2");
}
else
System.out.println("Test 3");
What are the possible values of x that will cause "Test 2 "
to be printed ?
0 to 4
Less than 0
5 to 9
10 and greater
None
What is the range of a char type?
0 to 216-1
Which of the following are true about >> and >>> operators?
>> performs a unsigned shift and >>> performs a rotate.
>> performs a signed shift and >>> performs an unsigned
shift.
>> performs an unsigned shift and >>> performs a signed
shift.
What are valid Java keywords
NULL
null
TRUE
implements
interface
instanceof
sizeof
Which of the following collection objects can be used for storing values
that may appear more than once and ordered ?
Map
List //dupes + ordered
Set
Collection // dupes + unordered
You want a component to retain its width, but not the height when resized.
How will you achieve this ?
Place the component in North or South in a BorderLayout
Place the component in the Center of a BorderLayout
Place the component in East or West in a BorderLayout
You have defined a class and sub classes of the same. But you don’t want
the methods of the super class to be overridden . what modifier you will use
for declaring the methods of the super class ?
final
What is the body of is a body code of a Thread
public void run()
public void start()
public void runnable()
public static void main(String args[])
What is the output of the following code?
int i = 0;
while(i-- > 0) {
System.out.println("The value of i is " + i);
}
System.out.println("Finished");
The value of i is 1
The value of i is 0
Finished
Compilation Error
Runtime Error
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]);
}
}
The value of 4th element is 4
The value of 4th element is null
The value of 4th element is 0
Null Pointer exception is raised
Runtime error, because the class is not instantiated
Which of the following is the correct class declaration for Car.java. See
to that it is a case-sensitive system
public class Car{
int in;
public Car(int inn){
in = inn
}
}
public class Car extends Truck, Vehicle{
int in;
public Car(int inn){
in = inn;
}
}
public class Car{
int in;
public abstract void raceCar()
{System.out.println("RaceCar");}
public Car(int inn){
in = inn;
}
}
public class Car{
int in;
public Car(int inn){
in = inn;
} }
Which of the following is true about Garbage Collection mechanism
Garbage Collection is carried out at predictable intervals
The programmer can write come complex code to perform garbage collection
The programmer can make objects eligible for garbage collection through
the reference variables
Garbage collection cannot be performed on objects which are referred by
the running threads.
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);
} }
- First Second
- Second First
- Compilation error
- Runtime error stating same name found in Super as well as in the Sub
class
java.awt.AWTEvent is a super class of all delegation model event classes.
There is one method called getID() in that class. What does that method
returns
text of the event
source of the event
ID of the event
What of the following cannot be added to a container ?
Applet
Panel
Frame
Component
Container
MenuComponent
How to initialise the variables in class Super from a constructor in the
same class(at line xx). Write a single line code without any spaces
class Super{
float x;
float y;
float z;
Super(float a, float b){
x = a;
y = b;
}
Super(float a, float b, float c){
//xx
z = c;
}
}
this(a,b);
What is true about inner classes?
Inner classes have to be instantiated only in the enclosing class
Inner classes can access all the final variables of the enclosing class
Inner classes cannot be static
Inner classes cannot be anonymous class
Inner classes can extend another class.
Consider the following hierarchy
Parent
------------------------------
| |
DerivedOne DerivedTwo
The following variables are initialised to null.
Parent P1;
DerivedOne D1;
DerivedTwo d2;
What will happen if the following assignment is made( take
the above into account)?
D1 = (DerivedOne) P1
- It is legal at compile time and illegal at run time
- It is legal at compile time and legal at run time // read q properly,
init to null
- It is illegal at compile time.
- It legal at compile time and may throw "CastClassException" at run time
Which modifiers are to be used to obtain the lock on the object
public
private
static
synchornized
lock
// Point X
public class Example
What can be possibly used at Point X
import java.awt.*;
package local.util;
class NoExample{}
protected class SimpleExample
public static final double PI = 3.14;
What is the range of int type
-231 to 231-1
What are the legal identifers in Java?
%employee
$employee
employ-ee
employee1
_employee
Which of the following are true about the listener interfaces in Java ?
awt listener menthods generally takes an argument which is an instance
of some subclass of java.awt.AWTEvent
When multiple listeners are added to a single component the order of
invocation of the listeners cannot be guaranteed
A single component can have multiple listeners added to it.
Given the following declaration.
String S1 = "Hello";
Which of the following are true ?
S1 = S1 >> 2;
S1 += "there";
S1 += 3;
char c = S1[2]; // Will give an error, use chatAt, as String is aclass
not a Array
Given the following String declarations and methods. What is the String
object referred by S1 after execution of these statements ?
String S1 = "Hello";
String S2 = "There";
S1.concat(" my friend");
S1.concat(" our friend");
S1 += S2;
HelloThere