Java Programming Questions and Answers
What gets printed on the standard output when the class below is compiled and executed. Select the one correct answer.
public class ShortCkt {
public static void main(String args[]) {
int i = 0;
boolean t = true;
boolean f = false, b;
b = (t || ((i++) == 0));
b = (f || ((i+=2) > 0));
System.out.println(i);
}
}
What gets printed on the standard output when the class below is compiled and executed. Select the one correct answer.
public class ShortCkt {
public static void main(String args[]) {
int i = 0;
boolean t = true;
boolean f = false, b;
b = (t & ((i++) == 0));
b = (f & ((i+=2) > 0));
System.out.println(i);
}
}
What gets printed on the standard output when the class below is compiled and executed. Select the one correct answer.
public class ShortCkt {
public static void main(String args[]) {
int i = 0;
boolean t = true;
boolean f = false, b;
b = (t && ((i++) == 0));
b = (f && ((i+=2) > 0));
System.out.println(i);
}
}
In the second assignment to variable b, the expression (i+=2) does not get evaluated.
What gets printed when the following program is compiled and run. Select the one correct answer.
class test {
public static void main(String args[]) {
int i,j,k,l=0;
k = l++;
j = ++k;
i = j++;
System.out.println(i);
}
}
In the following class definition, which is the first line (if any) that causes a compilation error. Select the one correct answer.
public class test {
public static void main(String args[]) {
char c;
int i;
c = 'A'; // 1
i = c; //2
c = i + 1; //3
c++; //4
}
}
It is not possible to assign an integer to a character in this case without a cast.
The signed right shift operator in Java is --. Select the one correct answer.
What is the result of compiling and running the following class. Select the one correct answer.
class Test {
public void methodA(int i) {
System.out.println(i);
}
public int methodA(int i) {
System.out.println(i+1);
return i+1;
}
public static void main(String args[]) {
Test X = new Test();
X.methodA(5);
}
}
Which of the following are valid constructors within a class Test
Which of the following are legal declaration and definition of a method.
What will the result of compiling and executing the following program. Select the one correct answer.
class Test { public static void main(String args[]) { int arr[] = new int[2]; System.out.println(arr[0]); } }