JAVA 部分
1.which are run-time exceptions() A.ArithmeticException B.ClassNotFoundException C.OutOfMemoryError D.ClassCastException E.InterruptedException F.IllegalArgumentException G.IndexOutOfBoundsException H.NullPointException a,d,f,g,h
2.Which Man class properly represents the relationship "Man has a best friend who is a Dog" d A.class Man extends Dog{} B.class Man implements{} C.class Man{private BestFriend dog;} D.class Man{private Dog bestFriend;} E.class Man{private Dog;} F.class Man{private BestFriend;}
3 Given: b,c,f interface Jumper{public void jump();} class Animal{}.. class Dog extends Animal{Tail tail;} class Beagle extends Dog implements Jumper{public void jump(){}}.. class Cat implements Jumper(public void jump(){}} Which are true( ) Multiple choices A.Cat is-a Aminal B.Cat is-a Jumper C.Dog is-a Animal D.Dog is-a Jumper E.Cat has-a Animal F.Beagle has-a Tail H.Beagle has-a Jumper 4 Given: a,b,c,d,e interface A{public int getValue();} class B implements A{public int getValue(){return 1;}} class C extends B{ 15 :insert code in here}
Which three code frgments,inserted individaully at line 15,make use (多选) A:public void add(C c){c.getValue();} B:public void add(B b){b.getValue();} C:public void add(A a){a.getValue();} D:public void add(A a,B b){a.getValue();} E:public void add(C c1,C c2){c1.getValue();}
5.丢失 丢失 6.Given B [2P]
String test = "This is test"; String[] tokens = test.split("¥s"); System.out.println(tokens.length); whta is the result( ) A.0 B.1 C.4 D.Compilation fails E.An exception is thrown at runtime
7. Given: C class Wow{ public static void go(short n){ System.out.print("short"); } public static void go(Short n){ System.out.print("SHORT"); } public static void go(Long n){ System.out.print("LONG"); } public static void main(String[] args){ Short n = 6; int m = 7; go(n); go(m); } } Which is th result? ( A. short LONG ) [2P]
B. SHORT LONG C. Compilation fails D.An exception is thrown at runtime 8.public class NamedCounter{ private final String name; private int count; public NamedCounter(String name){ this.name = name; } public String getName(){ return name; } public void increment(){ count++; } public int getCount(){ return count; } public void reset(){ count = 0; } } Which changes should be made to adapt this class to be used savely by threads? a,b,c,e [Multiple choices] A.declare reset() using the synchronized keyword B.declare getName() using the synchronized keyword C.declare getCount() using the synchronized key
word D.declare the constructor using the synchronized keyword E.declare increment() using the synchronized keyword 9、Which two statements are true?( ) [2P] 、 (Choose two) A.It is poossible for more than two threads to deadlock at once. B.The JVM implementation guarantees that multiple threads cannot enter into a deadlocked state. C.Deadlocked threads release once their sleep() method's sleep duration has expired. D.Deadlocking can occur only when the wait(),notify(),and notifyAll(
) methods are use incorrectly. E.(看不到) F.(看不到) ( )[2P]
10.Given: b, Interface Foo{} class Alpha implements Foo{} class Beta extends Alpha {} class Delta extends Beta{ public static void main(String[] args){ Beta x=new Beta(); 16.//insert code here } } Which code,inserted at line16,will cause a java.lang.ClassCastException ( ) A.Alpha a=x; B.Foo f=(Delta)x; C.Foo f=(Alpha)x; D.Beta b=(Beta)(Alpha)x; 11.How many String objects are generated by the following statement?( String s=new String("xyz")[3P] A.0 B.1 C.2 D.None of above )
12.Compare the speeds when respectively search an element in hash table,list or array.( )[3P] A.List
this.value=value; title="Hello"; Hello(); } } ... Hello c=new Hello(5); System.out.println(c.title); what is the result?() A.Hello B.Hello World C.Compilation fails D.Hello World 5 E.The code runs with no output F.An exception is thrown at runtime 14. ? void waitForSignal(){ Object obj=new Object(); synchronized(Thread.currentThread()){ obj.wait(); obj.notify(); } } Which statement is true?() A.This code can throw an IllegalMonitorStateException B.This code can throw a TimeoutException after ten minutes C.Revesing the order of obj.wait() and obj.notify() might cause this method to complete normally D.A call to notify() or notifyAll() from another thread might cause this method to complete normally E.This code does NOT compile unless"obj.wait()" is replaced with"((Thread)obj).wait()" 15. class Person{ a String name="No name"; public Person(String nm){ name=nm; } } classEmployee extends Person{ String emplD="0000"; public Employee(String id){
super("dddd"); emplD=id; } } public class EmployeeTest{ public static void main(String[] args){ Employee e=new Employee("4321"); System.out.println(e.empID); } } what is the result?() A:4321 B:0000 C:An exception is thrown at runtime D:Compilation fails because of an error in line 18
16. D class Atom{ Atom(){ System.out.print("atom"); } } class Rock extends Atom{ Rock(String type){ System.out.print(type); } } public class Mountain extends Rock{ Mountain(){ super("granite"); new Rock("granite"); } public static void main(String[] a){ new Mountain(); } } what is the result?() A:Compilation fails
B:atom granite C:granite ...(看不清楚) D:atom granite atom granite 17.Given ? Public class Key{ Private long id1; Private long id2; 15.//class Key methods } A programmer is developing a class Key . that will be used as a key in java.util.HashMap. Which two methods should be overmidden to assure that Key works Answerly as a key. ( ) (Multiple choices) A. public int hashCode() B. public boolean equals(Key k) C. public int compareTo(Object o) D. public Boolean equals(Object o) E. public Boolean compareTo(Key k) 18. Check The Task Button Place code into the class so that it comp
lices and generates the output answer=42. Note Code options may be used more than once.
Class
public class Placehere { private Placehere object; public Placehere (Placehere object) { this.object = object; } Public Placehere getObject() { Return object; } Public static void main(String[] args) { Gen str = new Gen(“answer”); Gen intg = new Gen(42); System.out.println(str.getObject() + “=” +intg.getObject()); } }
Code Options
Gen Gen> Gen ? T --------------------------------Answer sample-------------------------Green choice1—>Yellow choice5
19.Given . a,b import java.util.*; public class Example{ public static void main(String[] a