Welcome to your Foundation Test - 2 Code - 819 Name Email Phone 1. Question: You want to find out whether two strings are equal or not, in terms of the actual characters within the strings. What is the best way to do this? Select 1 option(s): use String's equals method. use String's equalsIgnoreCase method. Use == operator. Use String's match method.2. Question: What will the following code print? String abc = "";abc.concat("abc");abc.concat("def");System.out.print(abc);Select 1 option(s): abc abcdef def It will print empty string (or in other words, nothing). It will not compile because there is no concat() method in String class.3. Question: How will you initialize a SimpleDateFormat object so that the following code will print the full name of the month of the given date? System.out.println(sdf.format(new Date()));Select 1 option(s): SimpleDateFormat sdf = new SimpleDateFormat("MMMM", Locale.FRANCE); SimpleDateFormat sdf = new SimpleDateFormat("M*", Locale.FRANCE); SimpleDateFormat sdf = new SimpleDateFormat("mmmm", Locale.FRANCE); SimpleDateFormat sdf = new SimpleDateFormat("mmm", Locale.FRANCE); SimpleDateFormat sdf = new SimpleDateFormat("MM", Locale.FRANCE);4. Question: Given the following code:abstract class Device{ String name; String number; String address; int frequency; abstract void setName(String name); abstract void connect(); abstract void disconnect(); abstract void call(String number); abstract void listenOn(int frequency); }interface Caller{ }interface Receiver{ }class Phone extends Device implements Caller{ }class TV extends Device implements Receiver{ }class WalkieTalkie extends Device implements Caller, Receiver{ }and the following requirements specification:1. Phone supports only the call operation. Users should have the ability to call a number, but not set the frequencey. Assume frequency is fixed at 0.2. TV supports only the listenOn operation. Users should have the ability to set the frequency using the listenOn method, but not change the number. Assume number is fixed at "0".3. WalkieTalkie contains both call and listenOn features. Users should have the ability to call a number using call as well as set frequency using listenOn.Which two changes together would allow you to achieve these specifications?Select 2 option(s): make Device an interface rather than an abstract class move String number from Device to Caller move int frequency from Device to Receiver make Device, rather than Phone, TV, and WalkieTalkie implement Caller and Receiver. move call from Device to Caller move listenOn from Device to Receiver5. Question: Which of the following are true about the "default" constructor? Select 1 option(s): It is provided by the compiler only if the class and any of its super classes does not define any constructor. It takes no arguments. A default constructor is used to return a default value. To define a default constructor, you must use the default keyword. It is always public.6. Question: Which of the following is/are valid double values for 10 million? (A million has 6 zeros) Select 1 option(s): double d = 10,000,000.0; double d = 10-000-000; double d = 10_000_000; double d = 10 000 000;7. Question: Which of the following are true about the "default" constructor? Select 2 option(s): It is provided by the compiler only if the class does not define any constructor. It initializes the instance members of the class. It calls the no-args constructor of the super class. It initializes instance as well as class fields of the class. It is provided by the compiler if the class does not define a 'no-args' constructor.8. Question: Which of the following are also known as "short circuiting logical operators"? Select 2 option(s): & || && | ^9. Question: Identify correct statements about a two dimensional array.Select 1 option(s): It is like a rectangular matrix where number of rows and number of columns may be different but each row or each column have the same number of elements. It is like a square matrix where number of rows and number of columns are same and each row or each column have the same number of elements. The number of rows and columns must be specified at the time it is declared. It is basically an array of arrays.10. Question: Consider the following class...class MyString extends String{ MyString(){ super(); }}The above code will not compile.Select 1 option(s): True False11. Question: Identify examples of autoboxing.Select 3 option(s): Float f = 2.0; Float f = 2.0f; Byte b = 2; Character c = 2; String s = "x";12. Question: What class of objects can be declared by the throws clause? Select 3 option(s): Exception Error Event Object RuntimeException13. Question: Identify the concrete classes that can be used to store key - value pairs?Select 2 option(s): java.util.HashMap java.util.Set java.util.SortedSet java.util.Map java.util.SortedMap java.util.TreeMap14. Question: Which interfaces does java.util.NavigableMap extend directly or indirectly? Select 2 option(s): java.util.SortedSet java.util.Map java.util.SortedMap java.util.TreeMap java.util.List15. Question: Consider the following code written by a new developer:while(true){ //additional valid code if(isDone()) break;}What can be done to make this code more readable?Select 1 option(s): Use a for loop Use the enhanced for loop use do-while instead of while. Use continue instead of break.16. Question: Which one of these is a proper definition of a class Car that cannot be sub-classed? Select 1 option(s): class Car { } abstract class Car { } native class Car { } static class Car { } final class Car { }17. Question: Which of the following standard functional interfaces returns void? Select 1 option(s): Supplier Function Predicate Consumer UnaryOperator18. Question: Given the following declaration, select the correct way to get the number of elements in the array, assuming that the array has been initialized.int[] intArr;Select 1 option(s): intArr[ ].length( ) intArr.length( ) intArr.length intArr[ ].size( ) intArr.size( )19. Question: A method with no access modifier defined in a class can be overridden by a method marked protected (assuming that it is not final) in the sub class.Select 1 option(s): True False20. Question: Which of the following elements is/are a must in a stream pipeline? Select 2 option(s): a source an intermediate operation a terminal operation a reduction operation a method reference a lambda expression21. Question: Which import statements are required to compile the following code? public class TestClass{ public static void main(String[] args) throws Exception { LocalDate d = LocalDate.of(2020, 1, 2); DateTimeFormattter df = DateTimeFormatter.ofPattern("yyyy MMM dd"); }}Select 2 option(s): import java.date.*; import java.util.*; import java.time.*; import java.time.format.*; import java.text.*; import java.util.date.*;22. Question: Which of the following tools support the --show-module-resolution option? Select 1 option(s): java javac jar jmod jdeps23. Question: Where, in a constructor, can you place a call to a super class's constructor ? Select 1 option(s): Anywhere in the constructor's body. As the first statement in the constructor. Only as the first statement and it can be called just like any other method call i.e. ClassName( ... ). You can't call super class's constructor in a base class as constructors are not inherited. None of the above.24. Question: Which of these statements are true? Select 2 option(s): All classes must explicitly define a constructor. A constructor can be declared private. A constructor can declare a return value. A constructor must initialize all the member variables of a class. A constructor can access the non-static members of a class.25. Question: In which of the following cases can the Console object be acquired? Select 1 option(s): When the JVM is started from an interactive command line with explicitly redirecting the standard input and output streams to Console. When the JVM is started from an interactive command line without redirecting the standard input and output streams. When the JVM is started in the background with the standard input and output streams directed to Console. When the JVM is started in the background without redirecting the standard input and output streams.26. Question: Which of the following are required to construct a Locale? Select 1 option(s): language region country time zone state culture27. Question: Which of the following collection implementations are thread-safe? Select 1 option(s): ArrayList HashSet HashMap TreeSet None of the Above.28. Question: Which of the following access control keywords can be used to enable all the subclasses to access a method defined in the base class? Select 2 option(s): public private protected No keyword is needed.29. Question: Which of the following statements are true? Select 2 option(s): The extends keyword is used to specify inheritance. subclass of a non-abstract class cannot be declared abstract. subclass of an abstract class can be declared abstract. subclass of a final class can be abstract. A class, in which all the members are declared private, cannot be declared public.30. Question: Which of the following are correct about java.util.function.Predicate? Select 1 option(s): It is an interface that has only one abstract method (among other non-abstract methods) with the signature -public void test(T t); It is an interface that has only one abstract method (among other non-abstract methods) with the signature -public boolean test(T t); It is an abstract class that has only one abstract method (among other non-abstract methods) with the signature -public abstract void test(T t); It is an abstract class that has only one abstract method (among other non-abstract methods) with the signature -public abstract boolean test(T t);31. Question: Which of the following method calls can be applied to a String object? Select 4 option(s): repeat(int ) equalsIgnoreCase(String) prune() append() intern() compareTo(String )32. Question: Which of the following are valid declarations in a class? Select 1 option(s): abstract int absMethod(int param) throws Exception; abstract native int absMethod(int param) throws Exception; float native getVariance() throws Exception; abstract private int absMethod(int param) throws Exception;33. Question: What is meant by "encapsulation" ? Select 1 option(s): There is no way to access member variable. There are no member variables. Member fields are declared private and public accessor/mutator methods are provided to access and change their values if needed. Data fields are declared public and accessor methods are provided to access and change their values.34. Question: Identify the correct statement about i18n.Select 2 option(s): I18N class allows you to port your code for multiple regions and/or languages. You should use Locale and formatter objects such as NumberFormat and DateFormat to generate locale specific output. The i18n method of NumberFormat and DateFormat allows you to generate locale specific output. Using default locale for NumberFormat and DateFormat automatically ensures that the formatted text will be localized to the location setting of the machine on which the code is run.(Assuming that default locale hasn't been explicitly changed by any means.) i18n stands for Internationalization and it is handled automatically by Java.35. Question: Which of the following interface is suitable for a class that stores associations of keys to values? Select 1 option(s): Collection SortedSet Map Set None of the above.36. Question: Identify the correct statements regarding JDBC.Select 1 option(s): The JDBC Driver must be loaded explicitly in the code before attempting to create a connection to the database. Starting JDBC 4.0, the JDBC Driver class is not required any more. Starting JDBC 4.0, the JDBC Driver class is not required to be loaded explicitly in the code any more. JDBC 4.0 allows loading multiple JDBC Drivers while previous versions did not.37. Question: Your application requires to store name value pairs such that the order of entries returned while iterating through the structure is deterministic. In other words, if you iterate over the same structure twice, the order of elements returned in both the iterations will be the same. Which of the following classes would you use?Select 2 option(s): HashMap LinkedHashSet Hashtable LinkedHashMap TreeMap38. Question: Consider the following variable declaration within the definition of an interface: int i = 10;Which of the following declarations defined in a non-abstract class, is equivalent to the above?Select 1 option(s): public static int i = 10; public final int i = 10; public static final int i = 10; public int i = 10; final int i = 10;39. Question: Your new question: Which of the following interfaces can be used to store a collection of non-duplicate/unique objects in an unordered fashion ?Select 1 option(s): List Map Set SortedList SortedSet40. Question: Which of the following options can be a part of a correct inner class declaration or a combined declaration and instance initialization ? (Assume that SimpleInterface and ComplexInterface are interfaces.)Select 2 option(s): private class C { } new SimpleInterface() { //valid code } new ComplexInterface(x) {//valid code} private final abstract class C { } new ComplexClass() implements SimpleInterface { }41. Question: Which clause(s) are used by a module definition that implements a service? Select 2 option(s): exports provides uses implements requires42. Question: Your application needs to load a set of key value pairs from a database table which never changes. Multiple threads need to access this information but none of them changes it.Which class would be the most appropriate to store such data if the values need not be kept in a sorted fashion?Select 1 option(s): Hashtable HashMap Set TreeMap List43. Question: Which of these statements are true? Select 3 option(s): Non-static inner class cannot have static members. Objects of static nested classes can be created without creating instances of their Outer classes. Member variables in any nested class cannot be declared final. Anonymous classes cannot define constructors explicitly in Java code. Anonymous classes cannot be static.44. Question: Which of the following are standard Java annotations? Select 2 option(s): @NonNull @Interned @Repeatable @Retention45. Question: Consider the following code:public class MyClass { protected int value = 10;}Which of the following statements are correct regarding the field value?Select 1 option(s): It cannot be accessed from any other class. It can be read but cannot be modified from any other class. It can be modified but only from a subclass of MyClass. It can be read and modified from any class within the same package.46. Question: A try-with-resources statement requires ......Select 1 option(s): a catch block. a finally block. either a catch block or a finally block. neither a catch block nor a finally block.47. Question: Which of these statements are true? Select 2 option(s): A super( < appropriate list of arguments > ) or this( < appropriate list of arguments > ) call must always be provided explicitly as the first statement in the body of the constructor. If a subclass does not have any declared constructors, the implicit default constructor of the subclass will have a call to super( ). If neither super( ) or this( ) is declared as the first statement of the body of a constructor, then this( ) will implicitly be inserted as the first statement. super(< appropriate list of arguments >) can only be called in the first line of the constructor but this(< appropriate list of arguments >) can be called from anywhere. You can either call super(< appropriate list of arguments >) or this(< appropriate list of arguments >) but not both from a constructor.48. Question: An instance member ...Select 2 option(s): can be a variable, a constant or a method. is a variable or a constant. belongs to the class. belongs to an instance of the class. is same as a local variable.49. Question: Which of the following are benefits of an array over an ArrayList ? Select 2 option(s): It consumes less memory. Accessing an element in an array is faster than in ArrayList. You do not have to worry about thread safety. It implements Collection interface and can thus be passed where ever a Collection is required.50. Question: You are modeling a class hierarchy for living things. You have a class LivingThing which has an abstract method reproduce().Now, you want to have 2 concrete subclasses of LivingThing - Plant and Animal. Both do reproduce but the mechanisms are different. What would you do?Select 1 option(s): Overload the reproduce method in Plant and Animal classes Overload the reproduce method in LivingThing class. Override the reproduce method in Plant and Animal classes Either overload or override reproduce in Plant and Animal classes, it depends on the preference of the designer.51. Question: Given:public class Employee{ String name; public Employee(){ }} Which of the following lines creates an Employee instance?Select 1 option(s): Employee e; Employee e = new Employee(); Employee e = Employee.new(); Employee e = Employee();52. Question: Anonymous inner classes always extend directly from the Object class.Select 1 option(s): True False53. Question: Which variables of the encapsulating class can an inner class access, if the inner class is defined in an instance method of the encapsulating class? Select 4 option(s): All static variables All final instance variables All instance variables All automatic variables. All final and effectively final automatic variablesTime is Up!