Which of the following is true?
public class A implements Comparable {
final int a;
A(final int a) {
this.a = a;
}
public int compareTo(A that) {
return this.a - that.a;
}
public static void main(String[] args) {
A a1 = new A(1);
A a2 = new A(2);
System.out.println(a1 > a2);
}
}
Answer
Which of the following is true?
public static final class Class {
static final int id = 1;
Class() {
}
static public int id() {
return id;
}
}
Answer
Which of the following is true?
public class Main {
public static void main() {
System.out.println("1234".length());
}
}
Answer
Which of the following is true?
public final class Main {
static final String s = "hello";
public void main(String[] args) {
System.out.println(s);
}
}
Answer
Which of the following is true?
public class A {
public String foo() {
return "a";
}
}
public class B extends A {
public String foo() {
return "b";
}
}
public class Main {
public static void main(String[] args) {
A a = (A) new B();
System.out.println(a.foo());
}
}
Answer
Which of the following is true?
public class Base {
public String toString() {
return "Base";
}
}
public class Derived extends Base {
public String toString() {
return "Derived";
}
}
public class Main {
public static void main(String[] args) {
Base b = new Derived();
System.out.println(b);
}
}
Answer
Which of the following is true?
public interface I {
public void method();
}
public abstract class C implements I {
private C() {
}
public static C getInstance() {
return new C();
}
public void method() {
}
}
Answer
What of following will happen?
public class A {
public void main(String[] args) {
A[] array = new A[10];
System.out.println(array.length);
}
}
Answer
Which of the following is true?
package a;
class A {
public void foo() {
System.out.println("a");
}
}
package b;
import a.A;
public class B extends A {
public void foo() {
System.out.println("b");
}
public static void main(String[] args) {
new B().foo();
}
}
Answer
What will be printed?
int a = 10;
System.out.println(a + ~a);
Answer
What will be printed?
String s1 = "a";
String s2 = s1;
s1 += "b";
System.out.println(s2);
Answer
What will be printed?
String s1 = "a";
String s2 = "a";
System.out.println(s1 == s2);
Answer
What will be printed?
int a = 1;
a += ++a * a;
System.out.println(a);
Answer
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);
}
}
}
Answer
What will be printed?
String s1 = new String("a");
String s2 = new String("a");
System.out.println(s1 == s2);
Answer
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");
}
Answer
What will be printed?
byte b = (byte) 128;
b >>>= 1;
System.out.println(b);
Answer
What will be printed?
int a = -1;
a = a >>> 1;
System.out.println(a);
Answer
What will be printed?
int a = -1;
a = a >> 1;
System.out.println(a);
Answer
What will be printed?
boolean value =
Double.POSITIVE_INFINITY == Double.POSITIVE_INFINITY;
System.out.println(value);
Answer
© 2017 QuizBucket.org