Шукаєте відповіді та рішення тестів для Course 40527? Перегляньте нашу велику колекцію перевірених відповідей для Course 40527 в moodle.jku.at.
Отримайте миттєвий доступ до точних відповідей та детальних пояснень для питань вашого курсу. Наша платформа, створена спільнотою, допомагає студентам досягати успіху!
Which statements are true for generics and generic arrays? a) At compile time, an unbounded generic type is resolved to type Object. b) When inheriting from a generic superclass, a generic subclass is NOT allowed to use more type parameters than the superclass. c) Constraining a type parameter T with an interface IF is implemented as: T extends IF. d) Given a type parameter T, an array can be declared and initialized as: T[] myArray = new T[10].
Decide, in which of the cases it is true that the type of variable s a type parameter?
a) class R implements Comparable<String> { String myComparable = "Hello World"; public int compareTo (String str) { return this.compareTo(str); } } R s;b) class B {} class A<T extends B> { T s; T getS() { return s; } }c) Object s = new String(“This is a string”);d) class T {} class S extends T {} T s = new S();
Which are correct uses of generics (here, R,S,T are type parameters)?a) class A<T,S> { T x; R y; } b) class A<T,S> { S x; T y; } c) class A { } class B <T extends Throwable> extends A { }
d) class A extends Thread {} class B<T> extends A { }
Which of the following statements are true?Assume that class WildAnimal { } and its subclass class Tiger extends WildAnimal { } exist. a) Using List<? extends WildAnimal> is a case of contravariance. b) Assume the following class List and its use (E is a parameter type): class List<E> { ... // list of elements of type E void add (E elem) { // add elem to list ... } } List<? super Tiger> animalList = new List<>(); It is possible to add an object of type WildAnimal to the list by calling: animalList.add(new WildAnimal()); c) Using List<? super Tiger> is a case of covariance. d) List<?> is compatible to a concrete List of any type.
--------------------------------- interface A_IF.java public interface A_IF { void methodA (); }
--------------------------------- class A.javapublic class A implements A_IF { @Override public void methodA() { System.out.println("A dummy implementation of methodA()"); } }--------------------------------- Main.java public class Main { public static void main(String[] args) { // Quiz statement } static void myMethod(A_IF a){ a.methodA(); }}
Which are (correct) uses of an anonymous class in Main.java, method main() (after "Quiz statement")?1) A_IF a = new A();2)A_IF a = new A_IF () { }; 3) myMethod(new A_IF() { @Override public void methodA() { System.out.println("A dummy implementation for methodA()"); } }); 4)A_IF a = new A_IF () { @Override public int methodA() { System.out.println("A dummy implementation for methodA()"); return 0; } };
Which of the following statements about instanceof are correct?1) instanceof is a binary operator.2) Assume that class A implements interface B, B b = new A(). Then, the expression "b instanceof A" is true.3) The following is given: B b = new A(). Then, the expression "b instanceof B" is true.4) Assume that A is a class and the variable a is of type A (A a;). The expression "a instanceof A" creates an instance of class A.
// Import the ArrayList class and the Iterator classimport java.util.ArrayList;import java.util.Iterator;import java.util.Objects;public class Main { public static void main(String[] args) { // Create an ArrayList - this is a list organized as an array // add(...) adds a new microorganism to the end of the list ArrayList<String> microOrganisms = new ArrayList<String>(); microOrganisms.add("Bacteria"); microOrganisms.add("Archaea"); microOrganisms.add("Protozoa"); microOrganisms.add("Algae"); microOrganisms.add("Fungi"); microOrganisms.add("Helminths"); microOrganisms.add("Viruses"); // Get the iterator // An ArrayList has a method iterator() that returns an iterator, similar to our example in class Iterator<String> it = microOrganisms.iterator(); // Statement placed here}Which statements print out "Helminths" (when entered in method main() after "Statement placed here")? 1) while (it.hasNext()) it.next(); System.out.println(it.next());2) while (it.hasNext()){ String s = it.next(); if (s.compareTo("Helminths")==0) { System.out.println(s); } }3) System.out.println(it.next());
4) String s = null; while (it.hasNext()){ if (it.next().compareTo("Helminths")==0) { s = it.next(); break; } } System.out.println(s);
---------------------------------- Data.javaimport java.time.LocalDate;class Data { int value; //value of transmitted data LocalDate time; //time of sending/receiving Data(int value) { this.value = value; this.time = LocalDate.now(); }}---------------------------------- Network.javaimport java.time.LocalDate;class Network { class Node { char id; //Node identifier final Node[] ports; // array of nodes the node is connected to Node(int size, char id) { this.ports = new Node[size]; this.id = id; } boolean send(Data data, int port) { //sends data to node on specified port if (ports[port] == null) return false; ports[port].receive(data); // data sent by calling receive from receiver node return true; } int broadcast(Data data) { //sends datagram to all ports to which a Node is connected for (int i = 0; i < ports.length; i++) { if (ports[i] != null) send (data, i); } return data.value; } void receive(Data data) { //when Node receives data, it logs the event to the console data.time = LocalDate.now(); System.out.println("Node " + id +" has received one transmission with content "+ data.value + " on " + data.time.toString()); } }}---------------------------------- Main.javapublic class Main { public static void main(String[] args) { //build Network Network n = new Network(); Node nodeA = n.new Node(3, 'A'); Node nodeB = n.new Node(3, 'B'); Node nodeC = n.new Node(3, 'C'); //connect nodes nodeA.ports[0] = nodeB; nodeA.ports[1] = nodeC; nodeB.ports[0] = nodeC; nodeC.ports[0] = nodeA; //create Data Data fromA = new Data(1906); //Birth year of Grace Hopper Data fromB = new Data(1912); //Birth year of Alan Turing Data fromC = new Data(1815); //Birth year of Ada Lovelace //broadcasts: send Data to all connnected nodes nodeA.broadcast(fromA); nodeB.broadcast(fromB); nodeC.broadcast(fromC); }} What is the issue that prevents this code from working (assume that all classes are in the same package)? 1) We cannot simply access the ports array using the indices - we would need an Iterator to get the values in the array. 2) Node is an inner class of Network - in order to use it as a data type in Main, we need to refer to it as Network.Node. 3) Broadcasts cannot work as the ports array contents is not visible. 4) It is not possible to define class Node within the scope of the class Network.