JavaCore Test 5

What is the range of values that can be specified for an int.

Which of the following statements is true?

What happens when the following program is compiled and executed with the command - java test.


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

What happens when the following program is compiled and then the command "java check it out" is executed.


class check
{
public static void main(String args[])
{
System.out.println(args[args.length-2]);
}
}

What happens when the following class is compiled and run.


public class test
{
public static void main(String args[])
{
int x = 0, y = 1, z;
if(x)
z = 0;
else
z = 1;
if(y)
z = 2;
else
z = 3;
System.out.println(z);
}
}

How can you ensure that the memory allocated by an object is freed.

All the wrapper classes (Integer, Boolean, Float, Short, Long, Double and Character) in java

What is the result of compiling and running this program?


public class test
{
public static void main(String args[])
{
int i, j;
int k = 0;
j = 2;
k = j = i = 1;
System.out.println(k);
}
}

What all gets printed when the following code is compiled and run.


class test
{
public static void main(String args[])
{
int i[] = {0,1};
try
{
i[2] = i[0] + i[1];
}
catch(ArrayIndexOutOfBoundsException e1)
{
System.out.println("1");
}
catch(Exception e2)
{
System.out.println("2");
}
finally
{
System.out.println(3);
}
System.out.println("4");
}
}

a. 1
b. 2
c. 3
d. 4

Which all lines are part of the output when the following code is compiled and run.


public class test {
public static void main(String args[]) {
for(int i = 0; i = 0; j--) {
if(i == j) continue;
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

What gets printed when the following code is compiled and run.


public class test {
public static void main(String args[]) {
int i = 1;
do {
i--;
} while (i > 2);
System.out.println(i);
}
}

The code snippet


if( "Welcome".trim() == "Welcome".trim() )
System.out.println("Equal");
else
System.out.println("Not Equal");

What will be Answer

A program needs to store the name, salary, and age of employees in years. Which of the following data types should be used to create the Employee class.
a. char
b. boolean
c. Boolean
d. String
e. int
f. double


Which all lines are part of the output when the following code is compiled and run.


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

Which of these is a legal definition of a method named m assuming it throws IOException, and returns void. Also assume that the method does not take any arguments.

Consider the following code snippet. What will be assigned to the variable fourthChar, if the code is executed?
String str = new String("Java");
char fourthChar = str.charAt(4);

To 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.

Which all lines are part of the output when the following code is compiled and run.


public class test
{
public static void main(String args[])
{
for(int i = 0; i = 0; j--)
{
if(i == j) break;
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

Which of the following are legal identifier names in Java.
a. %abcd
b. $abcd
c. 1abcd
d. package
e. _a_long_name

What 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[args.length-1]);
}
}

Schreibe einen Kommentar