Шукаєте відповіді та рішення тестів для *Програмування на Jаvа? Перегляньте нашу велику колекцію перевірених відповідей для *Програмування на Jаvа в dl.nure.ua.
Отримайте миттєвий доступ до точних відповідей та детальних пояснень для питань вашого курсу. Наша платформа, створена спільнотою, допомагає студентам досягати успіху!
Which of the following statements about design principles and design patterns are true? (Choose all that apply.)
What does the following code output?
1: public class Salmon {
2: int count;
3: public void Salmon() {
4: count = 4;
5: }
6: public static void main(String[] args) {
7: Salmon s = new Salmon();
8: System.out.println(s.count);
9: } }
Which of these statements compile? (Choose all that apply.)
What is the value of name after an instance of Eagle is serialized and then deserialized?
public class Bird implements Serializable {
protected transient String name = "Bridget";
public void setName(String name) { this.name = name; }
public String getName() { return name; }
public Bird() {
this.name = "Matt";
}
}
public class Eagle extends Bird implements Serializable {
{ this.name = "Janette"; }
public Eagle() {
this.name = "Daniel";
}
}
What statements are true about the following code? (Choose all that apply.)
public class Tail {}
public class Animal {
public String name;
}
public class Canine extends Animal {
public Tail tail;
}
public class Wolf extends Canine {}
What is true about the following code? (Choose all that apply)
public class Bear {
protected void finalize() {
System.out.println("Roar!");
}
public static void main(String[] args) {
Bear bear = new Bear();
bear = null;
System.gc();
} }
What is the result of the following class?
1: public class Box<T> {
2: T value;
3:
4: public Box(T value) {
5: this.value = value;
6: }
7: public T getValue() {
8: return value;
9: }
10: public static void main(String[] args) {
11: Box<String> one = new Box<String>("a string");
12: Box<Integer> two = new Box<>(123);
13: System.out.print(one.getValue());
14: System.out.print(two.getValue());
15: } }
What changes would need to be made to make the following immutable object pattern correct?(Choose all that apply.)
import java.util.List;
public class Duck {
private String name;
private List<Duck> ducklings;
public Duck(String name, List<Duck> ducklings) {
this.name = name;
this.ducklings = new ArrayList<Duck>(ducklings);
}
public String getName() { return name; }
public List<Duck> getDucklings() { return ducklings; }
public String hasDucklings(Predicate<Duck> p) {
return p.test(this) ? "Quack Quack": "";
}
}
What statements about the following class definition are true? (Choose all that apply.)
public class TicketManager {
private TicketManager() { super(); }
private static TicketManager instance;
public static synchronized TicketManager getInstance() { // k1
if (instance == null) instance = new TicketManager(); // k2
return instance;
}
private int tickets;
public int getTicketCount() { return tickets; }
public void makeTicketsAvailable(int value) { tickets += value; } // k3
public void sellTickets(int value) {
synchronized (this) { // k4
tickets -= value;
}
}
}
What is the result of the following program?
import java.util.*;
public class MyComparator implements Comparator<String> {
public int compare(String a, String b) {
return b.toLowerCase().compareTo(a.toLowerCase());
}
public static void main(String[] args) {
String[] values = { "123", "Abb", "aab" };
Arrays.sort(values, new MyComparator());
for (String s: values)
System.out.print(s + " ");
}
}