This presentation covers quiz questions prepared for the Core Java meetup on 1st October in Accion Labs. It has questions from "Java best practices", "bytecodes", and "elastic search".
18. Question
class Base {}
class DeriOne extends Base {}
class DeriTwo extends Base {}
class ArrayStore {
public static void main(String []args) {
Base [] baseArr = new DeriOne[3];
baseArr[0] = new DeriOne();
baseArr[2] = new DeriTwo();
System.out.println(baseArr.length);
}
}
A. This program prints the following: 3
B. This program prints the following: 2
C. This program throws an ArrayStoreException
D. This program throws an ArrayIndexOutOfBoundsException
19. Answer
class Base {}
class DeriOne extends Base {}
class DeriTwo extends Base {}
class ArrayStore {
public static void main(String []args) {
Base [] baseArr = new DeriOne[3];
baseArr[0] = new DeriOne();
baseArr[2] = new DeriTwo();
System.out.println(baseArr.length);
}
}
A. This program prints the following: 3
B. This program prints the following: 2
C. This program throws an ArrayStoreException
D. This program throws an ArrayIndexOutOfBoundsException
21. Question
import java.util.*;
class UtilitiesTest {
public static void main(String []args) {
List<Integer> intList = new LinkedList<>();
List<Double> dblList = new LinkedList<>();
System.out.println(intList.getClass() == dblList.getClass());
}
}
A. It prints: true
B. It prints: false
C. It results in a compiler error
D. It results in a runtime exception
22. Answer
import java.util.*;
class UtilitiesTest {
public static void main(String []args) {
List<Integer> intList = new LinkedList<>();
List<Double> dblList = new LinkedList<>();
System.out.println(intList.getClass() == dblList.getClass());
}
}
A. It prints: true
B. It prints: false
C. It results in a compiler error
D. It results in a runtime exception
24. Question
Consider the following program:
class AutoCloseableTest {
public static void main(String []args) {
try (Scanner consoleScanner = new Scanner(System.in)) {
consoleScanner.close(); // CLOSE
consoleScanner.close();
}
}
}
Which one of the following statements is correct?
A. This program terminates normally without throwing any exceptions
B. This program throws an IllegalStateException
C. This program throws an IOException
D. This program throws an AlreadyClosedException
E. This program results in a compiler error in the line marked with the
comment CLOSE
25. Answer
Consider the following program:
class AutoCloseableTest {
public static void main(String []args) {
try (Scanner consoleScanner = new Scanner(System.in)) {
consoleScanner.close(); // CLOSE
consoleScanner.close();
}
}
}
Which one of the following statements is correct?
A. This program terminates normally without throwing any exceptions
B. This program throws an IllegalStateException
C. This program throws an IOException
D. This program throws an AlreadyClosedException
E. This program results in a compiler error in the line marked with the
comment CLOSE
36. Question
Consider the following program and determine the output:
class Test {
public void print(Integer i) {
System.out.println("Integer");
}
public void print(int i) {
System.out.println("int");
}
public void print(long i) {
System.out.println("long");
}
public static void main(String args[]) {
Test test = new Test();
test.print(10);
}
}
A. The program results in a compiler error (“ambiguous overload”)
B. long
C. Integer
D. int
37. Answer
Consider the following program and determine the output:
class Test {
public void print(Integer i) {
System.out.println("Integer");
}
public void print(int i) {
System.out.println("int");
}
public void print(long i) {
System.out.println("long");
}
public static void main(String args[]) {
Test test = new Test();
test.print(10);
}
}
A. The program results in a compiler error (“ambiguous overload”)
B. long
C. Integer
D. int
40. Upcoming Bootcamps
• Docker Hands-on Bootcamp - Oct 15th
• AngularJS Bootcamp – Oct 22nd
• Modern Software Architecture – Nov 5th
• SOLID Principles & Design Patterns – Nov 19th
Please visit CodeOps.tech Upcomings section for
more details such as agenda/cost/trainer and
registration.
Use FLAT750
coupon code to
get Rs 750
discount