Java Test №6

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

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

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

Which of the following statements is true?
Which of the following statements are correct.
a. A Java program must have a package statement.
b. A package statement if present must be the first statement of the program (barring any comments).
c. If a Java program defines both a package and import statement, then the import statement must come before the package statement.
d. An empty file is a valid source file.
e. A Java file without any class or interface definitions can also be compiled.
f. If an import statement is present, it must appear before any class or interface definitions.

What is the result of compiling and running the following program.

class test
{
public static void main(String args[])
{
int[] arr = {1,2,3,4};
call_array(arr[0], arr);
System.out.println(arr[0] + "," + arr[1]);
}
static void call_array(int i, int arr[])
{
arr[i] = 6;
i = 5;
}
}
What gets displayed on the screen when the following program is compiled and run.

public class test
{
public static void main(String args[])
{
int x;
x = -3 >> 1;
x = x >>> 2;
x = x << 1;
System.out.println(x);
}
}
What all gets printed when the following gets compiled and run.
public class test {
public static void main(String args[]) {
String s1 = "abc";
String s2 = "abc";
if(s1 == s2)
System.out.println(1);
else
System.out.println(2);
if(s1.equals(s2))
System.out.println(3);
else
System.out.println(4);
}
}
How many numeric data types are supported in Java?
What would be the results of compiling and running the following class.
class test 
{
public static void main()
{
System.out.println("test");
}
}
Which of the following statements are true.
Which of the following are correct.
What all gets printed when the following gets compiled and run.
public class test {
public static void main(String args[]) {
String s1 = "abc";
String s2 = new String("abc");

if(s1 == s2)
System.out.println(1);
else
System.out.println(2);
if(s1.equals(s2))
System.out.println(3);
else
System.out.println(4);
}
}
Which of the following statements declare class Sample to belong to the payroll.admindept package?
Which of these are valid declarations for the main method?
Which expression can be used to access the last element of an array.
What is the result of compiling and running the following program.
public class test 
{
public static void main(String args[])
{
int i = -1;
i = i >> 1;
System.out.println(i);
}
}
Which of the following are legal array declarations.
a. int i[5][];
b. int i[][];
c. int []i[];
d. int i[5][5];
e. int[][] a;
The class java.lang.Exception is ?
Which of the following are valid declarations for the main method.
a. public static void main(String args[]);
b. public static void main(String []args);
c. final static public void main (String args[]);
d. public static int main(String args[]);
e. public static abstract void main(String args[]);
Which of the following statements are correct.
What all gets printed when the following gets compiled and run.
public class example {
public static void main(String args[]) {
int x = 0;
if(x > 0) x = 1;
switch(x) {
case 1: System.out.println(1);
case 0: System.out.println(0);
case 2: System.out.println(2);
break;
case 3: System.out.println(3);
default: System.out.println(4);
break;
}
}
}

A. 0
B. 1
C. 2
D. 3
E. 4

Kommentieren Sie den Artikel

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

Pruebas en línea