Java fundamental quiz collection that covers the syntax, data types and flow control of Java langage
This quiz is in Java quiz collection.
Start quizWhat is the outcome?
int value = (int) 2.0 / 3.0;
System.out.println(value);
What is wrong with this code?
public String readLine() {
try {
BufferedReader br =
new BufferedReader(new FileReader("file.txt"));
String line = br.readLine();
br.close();
return line;
} catch (Exception e) {
throw new RuntimeException(e);
}
}
What will be printed?
int i = 255;
byte b = (byte) i;
System.out.println(b);
What will be printed?
double value = -0.0;
System.out.println(value);
What will be printed?
boolean value = -0.0 == 0.0;
System.out.println(value);
What will be printed?
boolean value = Double.NaN == Double.NaN;
System.out.println(value);
What will be printed?
boolean value =
Double.POSITIVE_INFINITY == Double.POSITIVE_INFINITY;
System.out.println(value);
What will be printed?
int a = -1;
a = a >> 1;
System.out.println(a);
What will be printed?
int a = -1;
a = a >>> 1;
System.out.println(a);
What will be printed?
byte b = (byte) 128;
b >>>= 1;
System.out.println(b);
What will be the result of executing this code?
String s = null;
if ((s != null) || (!s.isEmpty())) {
System.out.println(s);
} else {
System.out.println("the string is null");
}
What will be printed?
String s1 = new String("a");
String s2 = new String("a");
System.out.println(s1 == s2);
What will be the result of running this code?
public class Test {
static boolean printAndReturn(boolean value) {
System.out.println(value);
return value;
}
public static void main(String[] args) {
if (printAndReturn(false) && printAndReturn(true)) {
System.out.println(true);
} else {
System.out.println(false);
}
}
}
What will be printed?
int a = 1;
a += ++a * a;
System.out.println(a);
What will be printed?
String s1 = "a";
String s2 = "a";
System.out.println(s1 == s2);
What will be printed?
String s1 = "a";
String s2 = s1;
s1 += "b";
System.out.println(s2);
What will be printed?
int a = 10;
System.out.println(a + ~a);
What will be the output of the program?
String a = "newspaper";
a = a.substring(5,7);
char b = a.charAt(1);
a = a + b;
System.out.println(a);
What will be the output of the program?
String a = "ABCD";
String b = a.toLowerCase();
b.replace('a','d');
b.replace('b','c');
System.out.println(b);
Which of the following is true?
public final class Main {
static final String s = "hello";
public void main(String[] args) {
System.out.println(s);
}
}
© 2017 QuizBucket.org