Programming Concepts using Java, Quiz 2
Consider the Java code given below.
class Printer { public <T extends Number> void printDetails(T value) { // LINE 1 System.out.println("Number: " + (value.doubleValue() * 3)); } public <U extends Number> void printDetails(U value) { // LINE 2 System.out.println("Double Number: " + (value.doubleValue() * 6)); } public <T> void printDetails(T value) { // LINE 3 System.out.println("Value: " + value); }}public class Test { public static void main(String[] args) { Printer p = new Printer(); p.printDetails(7); p.printDetails(3.5); p.printDetails("Java"); }}Choose the correct option.
Consider the Java code given below. class Printer { public <T extends Number> void printDetails(T value) { // LINE 1 System.out.println("Number: " + (value.doubleValue() * 3)); } public <U extends Number> void printDetails(U value) { // LINE 2 System.out.println("Double Number: " + (value.doubleValue() * 6)); } public <T> void printDetails(T value) { // LINE 3 System.out.println("Value: " + value); } } public class Test { public static void main(String[] args) { Printer p = new Printer(); p.printDetails(7); p.printDetails(3.5); p.printDetails("Java"); } } Choose the correct option. Consider the following Java code. import java.util.*; public class SetTest { public static void main(String[] args) { LinkedList<Integer> list = new LinkedList<Integer>(); list.add(20); list.add(30); list.add(10); list.add(40); HashSet<Integer> set1 = new HashSet<Integer>(list); TreeSet<Integer> set2 = new TreeSet<Integer>(set1); set2.addAll(set1); System.out.println(set2); } } Choose the correct option. Consider the following Java code. class User { private String username; private String password; public User(String u, String p) { assert u != null; // assert-1 assert p != null; // assert-2 username = u; password = p; } public boolean login() { assert !username.isEmpty(); // assert-3 assert password.length() >= 6; // assert-4 return username.equals("admin") && password.equals("admin123"); } } public class AssertTest { public static void main(String[] args) { User user = new User("admin", ""); System.out.println("Login status: " + user.login()); } } Identify the first `assert` statement that throws the `AssertionError` when the class is executed as: `java -ea AssertTest`