Java Test №7

Which of the following is not a return type?
What would happen when the following is compiled and executed.
public class Compare { 
public static void main(String args[]) {
int x = 10, y;
if(x = 10) y = 2;
System.out.println("y is " + y);
}
}
Given two non-negative integers a and b and a String str, what is the number of characters in the expression str.substring(a,b).
Which operator is used to perform bitwise exclusive or.
What all gets printed when the following program is compiled and run.
public class test {
public static void main(String args[]) {
int i=0, j=2;
do {
i=++i;
j--;
} while(j>0);
System.out.println(i);
}
}
If result = 2 + 3 * 5, what is the value and type of "result" variable?
What is the data type for the number 9.6352?
What would happen when the following is compiled and executed.
class example {
int x;
int y;
String name;
public static void main(String args[]) {
example pnt = new example();
System.out.println("pnt is " + pnt.name +
" " + pnt.x + " " + pnt.y);
}
}
The initial value of an instance variable of type String that is not explicitly initialized in the program is --.
The initial value of a local variable of type String that is not explicitly initialized and which is defined in a member function of a class.
What is the result of compiling and running the following program.
class test {
public static void main(String args[]) {
char ch;
String test2 = "abcd";
String test = new String("abcd");
if(test.equals(test2)) {
if(test == test2)
ch = test.charAt(0);
else
ch = test.charAt(1);
}
else {
if(test == test2)
ch = test.charAt(2);
else
ch = test.charAt(3);
}
System.out.println(ch);
}
}
What gets displayed on the screen when the following program is compiled and run.
public class test {
public static void main(String args[]) {
boolean x = true;
int a;
if(x) a = x ? 1: 2;
else a = x ? 3: 4;
System.out.println(a);
}
}
What is the result of compiling and running the following program.
class test {
public static void main(String args[]) {
int i,j=0;
for(i=10;i<0;i--) { j++; }
switch(j) {
case (0) :
j=j+1;
case(1):
j=j+2;
break;
case (2) :
j=j+3;
break;
case (10) :
j=j+10;
break;
default :
break;
}
System.out.println(j);
}
}
What gets displayed on the screen when the following program is compiled and run.
public class test {
public static void main(String args[]) {
boolean x = false;
int a;
if(x) a = x ? 1: 2;
else a = x ? 3: 4;
System.out.println(a);
}
}
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 > 1)
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

Assume that the value 3929.92 is of type "float". How to assign this value after declaring the variable "interest" of type float?
Which of the following are legal Java programs.
a. // The comments come before the package
package pkg;
import java.awt.*;
class C{}
b. package pkg;
import java.awt.*;
class C{}
c. package pkg1;
package pkg2;
import java.awt.*;
class C{}
d. package pkg;
import java.awt.*;
e. import java.awt.*;
class C{}
f. import java.awt.*;
package pkg;
class C {}
What is the number displayed when the following program is compiled and run.
class test {
public static void main(String args[]) {
test test1 = new test();
System.out.println(test1.xyz(100));
}
public int xyz(int num) {
if(num == 1) return 1;
else return(xyz(num-1) + num);
}
}
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, y;

x = 5 >> 2;
y = x >>> 2;
System.out.println(y);
}
}
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


Kommentieren Sie den Artikel

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

Pruebas en línea