interface DeclareStuff{
public static final int EASY = 3;
void doStuff(int t); }
public class TestDeclare implements DeclareStuff {
public static void main(String [] args) {
int x=5;
new TestDeclare().doStuff(++x);
}
void doStuff(int s) {
s += EASY + ++s;
System.out.println(”s “ + s);
}
}
What is the result?()
A. s 14
B. s 16
C. s 10
D. Compilation fails.
E. An exception is thrown at runtime.
您可能感兴趣的试卷
你可能感兴趣的试题
Given a class Repetition:
1. package utils;
2.
3. public class Repetition {
4. public static String twice(String s) { return s + s; }
5. }
and given another class Demo:
1. // insert code here
2.
3. public class Demo {
4. public static void main(String[] args) {
5. System.out.println(twice(”pizza”));
6. }
7. }
Which code should be inserted at line 1 of Demo.java to compile and run Demo to print“pizzapizza”?()
A. import utils.*;
B. static import utils.*;
C. import utils.Repetition.*;
D. static import utils.Repetition. *;
E. import utils.Repetition.twice();
F. import static utils.Repetition.twice;
G. static import utils.Repetition.twice;
Given a file GrizzlyBear.java:
1. package animals.mammals;
2.
3. public class GrizzlyBear extends Bear {
4. void hunt() {
5. Salmon s = findSalmon();
6. s.consume();
7. }
8. }
and another file, Salmon.java:
1. package animals.fish;
2.
3. public class Salmon extends Fish {
4. void consume() { /* do stuff */ }
5. }
Assume both classes are defined in the correct directories for theft packages, and that the Mammal class correctly defines the findSalmon() method. Which two changes allow this code to compile correctly?()
A. add public to the start of line 4 in Salmon.java
B. add public to the start of line 4 in GrizzlyBear.java
C. add import animals.mammals.*; at line 2 in Salmon.java
D. add import animals.fish.*; at line 2 in GrizzlyBear.java
E. add import animals.fish.Salmon.*; at line 2 in GrizzlyBear.java
F. add import animals.mammals.GrizzlyBear.*;at line 2 in Salmon.java
Given classes defined in two different files:
1. package util;
2. public class BitUtils {
3. private static void process(byte[] b) { }
4. }
1. package app;
2. public class SomeApp {
3. public static void main(String[] args) {
4. byte[] bytes = new byte[256];
5. // insert code here
6. }
7. }
What is required at line 5 in class SomeApp to use the process method of BitUtils?()
A. process(bytes);
B. BitUtils.process(bytes);
C. app.BitUtils.process(bytes);
D. util.BitUtils.process(bytes);
E. import util.BitUtils. *; process(bytes);
F. SomeApp cannot use the process method in BitUtils.
Given classes defined in two different files:
1. package util;
2. public class BitUtils {
3. private static void process(byte[] b) { }
4. }
1. package app;
2. public class SomeApp {
3. public static void main(String[] args) {
4. byte[] bytes = new byte[256];
5. // insert code here
6. }
7. }
What is required at line 5 in class SomeApp to use the process method of BitUtils?()
A. process(bytes);
B. BitUtils.process(bytes);
C. app.BitUtils.process(bytes);
D. util.BitUtils.process(bytes);
E. import util.BitUtils. *; process(bytes);
F. SomeApp cannot use the process method in BitUtils.
Given classes defined in two different files:
1. package util;
2. public class BitUtils {
3. public static void process(byte[]) { /* more code here */ }
4. }
1. package app;
2. public class SomeApp {
3. public static void main(String[] args) {
4. byte[] bytes = new byte[256];
5. // insert code here
6. }
7. }
What is required at line 5 in class SomeApp to use the process method of BitUtils?()
A. process(bytes);
B. BitUtils.process(bytes);
C. util.BitUtils.process(bytes);
D. SomeApp cannot use methods in BitUtils.
E. import util.BitUtils.*; process(bytes);
34. HashMap props = new HashMap();
35. props.put(”key45”, “some value”);
36. props.put(”key12”, “some other value”);
37. props.put(”key39”, “yet another value”);
38. Set s = props.keySet();
39. // insert code here
What, inserted at line 39, will sort the keys in the props HashMap?()
A. Arrays.sort(s);
B. s = new TreeSet(s);
C. Collections.sort(s);
D. s = new SortedSet(s);
Given:
ArrayList a = new ArrayList();
containing the values {“1”, “2”, “3”, “4”, “5”, “6”, “7”, “8”} Which code will return 2?()
A. Collections. sort(a, a.reverse()); int result = Collections.binarySearch(a, “6”);
B. Comparator c = Collections.reverseOrder(); Collections.sort(a, c); int result = Collections.binarySearch(a, “6”);
C. Comparator c = Collections.reverseOrder(); Collections.sort(a, c); int result = Collections.binarySearch(a, “6”,c);
D. Comparator c = Collections.reverseOrder(a); Collections.sort(a, c); int result = Collections.binarySearch(a, “6”,c);
E. Comparator c = new InverseComparator(new Comparator()); Collections.sort(a); int result = Collections.binarySearch(a, “6”,c);
import java.util.*;
public class LetterASort {
public static void main(String[] args) {
ArrayList
strings.add(‟aAaA”);
strings.add(”AaA”);
strings.add(‟aAa”);
strings.add(”AAaa”);
Collections.sort(strings);
for (String s: strings) { System.out.print(s + “ “); }
}
}
What is the result?()
A. Compilation fails.
B. aAaA aAa AAaa AaA
C. AAaa AaA aAa aAaA
D. AaA AAaa aAaA aAa
E. aAa AaA aAaA AAaa
F. An exception is thrown at runtime.
public static void search(List
list.clear();
list.add(”b”);
list.add(”a”);
list.add(”c”);
System.out.println(Collections.binarySearch(list, “a”));
}
What is the result of calling search with a valid List implementation?()
A.0
B.1
C.a
D.b
E.c
F.The result is undefined.
Given:
int[] myArray=newint[] {1, 2,3,4, 5};
What allows you to create a list from this array?()
A. List myList = myArray.asList();
B. List myList = Arrays.asList(myArray);
C. List myList = new ArrayList(myArray);
D. List myList = Collections.fromArray(myArray);
最新试题
Which two changes, taken together, would guarantee the output: 1, 2, 3, 4, 5?()
What is the result?()
A programmer iterates over the TreeSet and prints the name of each Drink object. What is the result?()
Which statement is true?()
Which three will compile and run without exception?()
A programmer is developing a class Key, that will be used as a key in a standard java.util.HashMap. Which two methods should be overridden to assure that Key works correctly as a key?()
What is the result?()
What is the result?()
Which two are possible results?()
What is the appropriate definition of the hashCode method in class Person?()