class Foo {
Object methodA() { return null; }
String methodB() { return ""; }
}
class Bar extends Foo {
// int methodA() { return 0; } // Line 1
// Integer methodA() { return 0; } // Line 2
// Object methodB() { return null; } // Line 3
// void methodB() { } // Line 4
// StringBuilder methodB() { } // Line 5
}
Options are :
Integer[] array = {1, 2};
List<Integer> list = Arrays.asList(array);
list.set(0, 2);
array[1] = 1;
System.out.println(Arrays.toString(array));
System.out.println(list);
Options are :
public class Test {
public static void main(String[] args) {
Test test = new Test();
test.loop(0);
}
void loop(int number) {
for ( ; ; ) {
if (number < 10) {
System.out.println(number);
break;
}
}
}
}
Options are :
import java.util.List;
package test;
public class MyTest {
public static void main(String[] args) {
List<Integer> numbers = List.of();
for (int number : numbers) {
System.out.print(number + "===");
}
}
}
Options are :
List strings = new ArrayList<>();
strings.addAll(List.of("A", "B"));
System.out.println(strings.remove(0));
System.out.println(strings.remove("A"));
System.out.println(strings.remove("B"));
What is the output of the given code fragment?
Options are :
class Foo {
Foo(String input) /* Position 1 */ {
if (input == null) {
return; /* Position 2 */
} else {
throw new IOException();
}
}
}
public class Test {
public static void main(String[] args) {
try {
new Foo(null /* Position 3 */)
} catch (Exception /* Position 4 */) e{
e.printStackTrace();
}
}
}
Options are :
package foo;
public abstract class MyFoo {
abstract void m();
}
And:
package bar;
import foo.MyFoo;
public class MyBar extends MyFoo {
void m() {
// A valid body
}
}
Options are :
class Foo {
static String foo = init();
Foo() {
System.out.println("Super");
}
static String init() {
System.out.println("Init Foo");
return "Foo";
}
}
public class Bar extends Foo {
static String bar = init();
Bar() {
System.out.println("Sub");
}
static String init() {
System.out.println("Init Bar");
return "Bar";
}
public static void main(String[] args) {
new Bar();
}
}
Options are :
public class Test {
public static void main(String[] args) {
Test test = new Test();
int sum = test.sumUp(List.of(1, 2, 3, 4, 5));
System.out.println(sum);
}
int sumUp(List<Integer> numbers) {
int sum = 0;
myLabel:
do {
for (int number : numbers) {
if (number == 3) break myLabel;
sum += number;
}
} while (sum < 15);
return sum;
}
}
Options are :
package test;
class Data {
/* Insert here */ String s;
}
Options are :
var list = new ArrayList<>(); // Line 1
var i1 = 1, i2 = 2; // Line 2
var string; // Line 3
var object = null; // Line 4
var array = {1, 2}; // Line 5
Options are :
List list1 = new ArrayList<>(List.of(1, 2, 3, 4, 5));
List list2 = new ArrayList<>(List.of(1, 2, 3));
list1.removeIf(e -> e % 2 == 0);
list1.retainAll(list2);
System.out.println(list1);
Options are :
Options are :
interface Foo {
abstract void m(); // Line 1
}
class Bar implements Foo {
@Override // Line 2
void m() { } // Line 3
}
Options are :
public class Test {
public static void main(String[] args) {
int[] array = {0, 2, 4};
int index;
int element = array[index = 1]++;
System.out.println(index + ": " + array[index] + " -> " + element);
}
}
Options are :
String select(int number) {
String output;
switch (number) {
case 0:
default:
case 1:
output = "positive";
}
return output;
}
Options are :
package my.test;
public class Main {
public static void main(String[] args) {
System.out.println("Hello");
}
}
This class is included in a module called my.test.Main, which is wrapped in a JAR file called mytest.jar. Which of the following command executes the given program when the JAR file is put in the working directory?
Options are :
interface MyFoo {
int number = 0;
void calculate(int arg);
}
class MyBar implements MyFoo {
int number = 10;
public void calculate(int arg) {
number += arg;
}
}
class Test {
public static void main(String[] args) {
MyFoo foo = new MyBar();
foo.calculate(20);
System.out.println(foo.number);
}
}
Options are :
public class Test {
static int getNumber() throws Exception {
throw new Exception("test");
}
public static void main(String[] args) {
int i = 0;
try {
int j = 1 / i * getNumber();
} catch (Exception e) {
System.out.println(j + ": " + e.getMessage());
}
}
}
Options are :
class Foo {
public void m() {
System.out.println("Foo");
}
}
class Bar extends Foo {
public void m(String arg) throws Exception { // Line 1
System.out.println(arg);
}
}
public class Test {
public static void main(String[] args) {
Foo foo = new Bar();
foo.m("Bar"); // Line 2
Bar bar = (Bar) foo;
bar.m(); // Line 3
}
}
Options are :
Options are :
int select(List<Integer> list) {
for (int i : list) {
switch (i) {
case 1:
return i;
break; // Line 1
default:
System.out.println("default");
}
}
return 0;
}
Options are :
String s1 = "Hello";
String s2 = " ";
String s3 = "World!";
String s = s1 + s2 + s3;
Options are :
class Foo {
protected static int myField = 2019;
protected static Object myMethod() {
return myField;
}
}
public class Bar extends Foo {
public String myField = "Bar";
public static String myMethod() {
return new Bar().myField;
}
public static void main(String[] args) {
Foo foo = new Bar();
System.out.println(foo.myField);
System.out.println(foo.myMethod());
}
}
Options are :
int a = 1, b = 2, c = 3, d = 4;
a = b = c;
b = -d;
c *= c;
d %= a;
System.out.println(a + " " + b + " " + c + " " + d);
Options are :
interface Foo {
void methodA();
}
abstract class Bar /* Position 1 */ {
/* Position 2 */
public abstract void methodB();
}
public class FooBar /* Position 3 */ {
@Override /* Position 4 */
public void methodA() {
// a valid body
}
@Override /* Position 5 */
public void methodB() {
// a valid body
}
}
Options are :
try {
throw new IOException();
} catch (RuntimeException e1) { // Line 1
System.out.println("RuntimeException");
} catch (Exception e2) { // Line 2
System.out.println("Exception");
} catch (IOException e3) { // Line 3
System.out.println("IOException");
}
Options are :
String[][] matrix = {?{"a", "b", "c"}, {"d", "e", "f"}};
// Line 1
System.out.println(element);
Options are :
String text = "This is it";
int index = text.indexOf("is");
text = text.substring(index + 3);
text.substring(1, 3);
System.out.println(text);
Options are :
int x = 1, y = 2, z = 3;
x -= y += z;
System.out.println(x + " " + y);
Options are :
abstract class Foo {
Foo(String arg) { // Line 1
System.out.println(arg);
}
}
public class Bar extends Foo {
Bar(String arg) { // Line 2
super(arg); // Line 3
}
public static void main(String[] args) {
Foo foo = new Foo("test"); // Line 4
Bar bar = new Bar("test"); // Line 5
}
}
Options are :
class Foo {
CharSequence sequence;
Foo(CharSequence sequence) {
this.sequence = sequence;
}
}
public class Test {
public static void main(String[] args) {
Foo foo1 = new Foo(); // Line 1
Foo foo2 = new Foo("string"); // Line 2
Foo foo3 = new Foo(new StringBuilder("builder")); // Line 3
}
}
Options are :
StringBuilder builder = new StringBuilder("ABCD");
builder.replace(1, 3, "C").insert(4, "Q");
System.out.println(builder);
Options are :
Options are :
interface Foo {
int fieldA = 0;
int fieldB = 0;
void methodA();
static void methodB() {
// a valid body
}
}
interface Bar extends Foo {
int fieldA = 1; // Line 1
int fieldB = Foo.fieldB; // Line 2
static void methodA() { // Line 3
// a valid body
}
void methodB(); // Line 4
}
Options are :
Given the bar module:
module bar {
requires foo;
exports bar;
}
With a class:
package bar;
public class MyBar { }
And here's the foo module:
module foo {
requires bar;
}
With another class:
package foo;
import bar.MyBar;
public class MyFoo {
public static void main(String[] args) {
new MyBar();
}
}
Options are :
I am Pavankumar, Having 8.5 years of experience currently working in Video/Live Analytics project.