Java Test №4

At what stage in the following method does the object initially referenced by s becomes available for garbage collection.

void method X() {
String r = new String("abc");
String s = new String("abc");
r = r+1; //1
r = null; //2
s = s + r; //3
} //4
Which of the following statements is preferred to create a string "Welcome to Java Programming"?
What all gets printed on the standard output when the class below is compiled and executed by entering "java test lets see what happens".

public class test
{
public static void main(String args[])
{
System.out.println(args[0]+" "+args.length);
}
}

a. java
b. test
c. lets
d. 3
e. 4
f. 5
g. 6

In implementing two classes Employee and Manager, such that each Manager is an Employee, what should be the relationship between these classes.
Which all lines are part of the output when the following code is compiled and run. Select the six correct answers.

public class test
{
public static void main(String args[])
{
outer:
for(int i = 0; i = 0; j--)
{
if(i == j) continue outer;
System.out.println(i + " " + j);
}
}
}
}

a. 0 0
b. 0 1
c. 0 2
d. 0 3
e. 1 0
f. 1 1
g. 1 2
h. 1 3
i. 2 0
j. 2 1
k. 2 2
l. 2 3
m. 3 0
n. 3 1
o. 3 2
p. 3 3

String s = new String("xyz");
Assuming the above declaration, which of the following statements would compile.
Which of the following statements is true?
What happens when the following program is compiled and run.

public class example
{
int i = 0;
public static void main(String args[])
{
int i = 1;
i = change_i(i);
System.out.println(i);
}
public static int change_i(int i)
{
i = 2;
i *= 2;
return i;
}
}
Select the one most appropriate answer. What is the purpose of method parseInt defined in Integer class.
Which of the following statements related to Garbage Collection are correct.

a. It is possible for a program to free memory at a given time.
b. Garbage Collection feature of Java ensures that the program never runs out of memory.
c. It is possible for a program to make an object available for Garbage Collection.
d. The finalize method of an object is invoked before garbage collection is performed on the object.
What kind of thread is the Garbage collector thread is?
What happens when the following program is compiled and run.

public class example
{
int i = 0;
public static void main(String args[])
{
int i = 1;
change_i(i);
System.out.println(i);
}
public static void change_i(int i)
{
i = 2;
i *= 2;
}
}

What should be done to invoke the run() method on a thread for an object derived from the Thread class.
If a base class has a method defined as
void method() { }
Which of the following are legal prototypes in a derived class of this class.
a. void method() { }
b. int method() { return 0;}
c. void method(int i) { }
d. private void method() { }

In which all cases does an exception gets generated.
int i = 0, j = 1;
a. if((i == 0) || (j/i == 1))
b. if((i == 0) | (j/i == 1))
c. if((i != 0) && (j/i == 1))
d. if((i != 0) & (j/i == 1))

When a thread terminates its processing, into what state that thread enters?
What happens when the following program is compiled and run.

public class example
{
int i[] = {0};
public static void main(String args[])
{
int i[] = {1};
change_i(i);
System.out.println(i[0]);
}
public static void change_i(int i[])
{
i[0] = 2;
i[0] *= 2;
}
}
What is the default priority of a newly created thread?
Which of the following statements are true.
a. The wait method defined in the Thread class, can be used to convert a thread from Running state to Waiting state.
b. The wait(), notify(), and notifyAll() methods must be executed in synchronized code.
c. The notify() and notifyAll() methods can be used to signal and move waiting threads to ready-to-run state.
d. The Thread class is an abstract class.

Which keyword when applied on a method indicates that only one thread should execute the method at a time.

Kommentieren Sie den Artikel

Bitte geben Sie Ihren Kommentar ein!
Bitte geben Sie hier Ihren Namen ein

Pruebas en línea