What is the output of this code?
String s1 = "abc";
String s2 = "abc";
String s3 = new String("abc");
System.out.println(s1 == s2);
System.out.println(s1 == s3);
What is the output of this code involving static and instance initialization order?
class A {
static { System.out.println("static A"); }
{ System.out.println("instance A"); }
A() { System.out.println("constructor A"); }
}
new A();
new A();
What is the output?
public class Test {
public static void main(String[] args) {
System.out.println(10 / 3);
System.out.println(10.0 / 3);
System.out.println(10 % 3);
}
}
What happens when you compile and run this code?
class Parent { static void greet() { System.out.println("Parent"); } }
class Child extends Parent { static void greet() { System.out.println("Child"); } }
Parent p = new Child();
p.greet();
What is the output of this array comparison?
int[] a = {1, 2, 3};
int[] b = {1, 2, 3};
System.out.println(a == b);
System.out.println(a.equals(b));
System.out.println(Arrays.equals(a, b));
What does this output?
class Base {
int x = 10;
int getX() { return x; }
}
class Derived extends Base {
int x = 20;
int getX() { return x; }
}
Base obj = new Derived();
System.out.println(obj.x);
System.out.println(obj.getX());
What is the difference between checked exception wrapping in streams' lambdas — why can't you throw checked exceptions inside a lambda directly used in a stream?