Looking for 367.044, VL Vertiefung Softwareentwicklung, Karin Anna Hummel, 2024S test answers and solutions? Browse our comprehensive collection of verified answers for 367.044, VL Vertiefung Softwareentwicklung, Karin Anna Hummel, 2024S at moodle.jku.at.
Get instant access to accurate answers and detailed explanations for your course questions. Our community-driven platform helps students succeed!
The following code contains the classes Hobbit, Ring, and the creation and start of three Hobbit threads in class Main / main().
class Ring { String owner = "Who knows";} class Hobbit extends Thread { String name; Ring ring; Hobbit (String name, Ring ring) { this.name = name; this.ring = ring; } @Override public void run() { ring.owner = name; System.out.println(name + " says: the precious is mine, " + ring.owner); }}// Class Main public static void main(String[] args) { Ring ring = new Ring(); Hobbit gollum; Hobbit bilbo; Hobbit frodo; gollum = new Hobbit("Gollum",ring); bilbo = new Hobbit("Bilbo Baggins",ring); frodo = new Hobbit("Frodo Baggins",ring); gollum.start(); bilbo.start(); frodo.start(); }
Which of the following statements assure mutual exclusion and thus, lead to the expected, thread-safe output?
a) Changing run() in class Hobbit to:
@Overridesynchronized public void run() { ring.owner = name; System.out.println(name + " says: the precious is mine, " + ring.owner);}
b) Changing run() in class Hobbit to:
@Overridepublic void run() { synchronized(ring) { ring.owner = name; System.out.println(name + " says: the precious is mine, " + ring.owner); }}
c) Changing the creation of the threads in Class Main (main()) as follows:
synchronized (ring) { gollum = new Hobbit("Gollum",ring); bilbo = new Hobbit("Bilbo Baggins",ring); frodo = new Hobbit("Frodo Baggins",ring);}
d) Changing the starting of the threads in main() as follows:
synchronized (ring) { gollum.start(); bilbo.start(); frodo.start();}
Which of the following statements start a new thread?
a)
Thread t1 = new Thread(()-> System.out.println("I want to run ..."));t1.start();
b)
Thread t2 = new Thread(new Runnable() { @Override public void run() { System.out.println("I want to run ..."); }});t2.start();
c)
Thread t3 = new Thread (()->System.out.println("I want to run ..."));t3.run();
d)
Runnable t4 = () -> System.out.println("I want to run");t4.start();
Which statements are true for generics and generic arrays? a) At compile time, an unbounded generic type is resolved to type Object. b) When deriving a generic class, this 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 implements IF. d) Given a type parameter T, an array can be declared and initialized as: T[] myArray = new T[10].
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) In class List<E>, where E is a paramter type, the method add is implemented that allows to add an element of type E to the list: void add (E elem) {…} Can you build a concrete List (list with concretized types) for adding and storing WildAnimal objects? c) Using List<? super Tiger> is a case of contravariance. d) List<?> is compatible to a concrete List of any type.
In which of the following statements is the variable s defined as a generic type?a) String s = “This is a string”;b) Object s = new String(“This is a string”);c) class B {} class A<T extends B> { T s; T getS() { return s; } }d) class T {} class R extends T {} T s = new R();
Which are correct uses of generics (R,S,T are type parameters)?a) class A <T,S> { S x; T y; } b) class A <T,S> { T x; R y; } c) class A { } class B <T extends Throwable> extends A { }
d) class A extends Throwable {} class B <T> extends A { }