相关考题
-
单项选择题
1. import java.util.*; 2. class AddStuff { 3. public static void main(String [] args) { 4. TreeSet〈String〉 s = new TreeSet〈String〉(); 5. s.add("one"); 6. s.add("two"); 7. // insert code here 8. for(String s2 : sorted) 9. System.out.print(s2 + " "); 10. } 11. } 和四个代码片段: s1. SortedSet sorted = s.tailSet(s.first()); s2. SortedSet〈String〉 sorted = s.tailSet(s.first()); s3. SortedSet sorted = (SortedSet)s.tailSet(s.first()); s4. SortedSet sorted = (SortedSet〈String〉)s.tailSet(s.first()); 分别插入到第7行,哪项可以编译?()
A.s1
B.s2
C.s2 和 s3
D.s2 和 s4 -
单项选择题
class Bird { static void talk() { System.out.print("chirp "); } } class Parrot extends Bird { static void talk() { System.out.print("hello "); } public static void main(String [] args) { Bird [] birds = {new Bird(), new Parrot()}; for( Bird b : birds) b.talk(); } } 结果为:()
A.chirp chirp
B.chirp hello
C.hello hello
D.编译失败 -
单项选择题
现有: 1. interface Animal { 2. void eat(); 3. } 4. 5. // insert code here 6. 7. public class HouseCat extends Feline { 8. public void eat() { } 9. } 和五个声明: abstract class Feline implements Animal { } abstract class Feline implements Animal { void eat(); } abstract class Feline implements Animal { public void eat(); } abstract class Feline implements Animal { public void eat() { } } abstract class Feline implements Animal { abstract public void eat(); } 分别插入到第5行,有几个可以通过编译?()
A.0
B.1
C.2
D.3
