房天下 > 房天下问答 > 业主生活 > 其他
  • Java 選擇題

    2. Which of the following statements are true?I. ArrayLists cannot be used in situations where the number of elements never changes.II. ArrayLists are useful in situations where the number of elements stored is likely to change over time.III. The size of an Arraylist can never exceed its initial capacity.A. I onlyB. II onlyC. III onlyD. II and III onlyE. I, II, and III3. Which of the following code fragments successfully reverses the order of the elements in the ArrayList t?I. // t is an ArrayListfor ( int i = 0 ; i < t.size() ; i++ )t.add( t.get( i ) );II. // t is an ArrayListfor ( int i = 0 ; i < t.size() ; i++ ){t.add( t.get( 0 ) );t.remove( 0 );}III. // t is an ArrayListfor ( int i = 0 ; i < t.size() ; i++ ){t.remove( t.size() - 1 - i );t.add( t.get( i ) );}A. I onlyB. II onlyC. III onlyD. I, II and IIIE. None of the above.4. An ArrayList is needed to keep track of twelve ints. Which of the following statements successfully creates an ArrayList that can be used for this purpose?I. ArrayList<int> a = new ArrayList<int>( 25 );II. ArrayList<Integer> a = new ArrayList<Integer>( 25 );III. ArrayList<Integer> a = new ArrayList<Integer>();A. I onlyB. II onlyC. III onlyD. II and III onlyE. I, II, and III The remaining questions on this test are concerned with the Person and Family classes, defined as follows:*public class Person { private String myName; private int myAge; private Person myNextSibling; public Person( String name, int age ) { myName = name; myAge = age; myNextSibling = null; } public void birthday() { myAge++; } public int getAge() { return myAge; } public String getName() { return myName; } public void setNextSibling( Person p ) { myNextSibling = p; } public Person getNextSibling() { return myNextSibling; } }*public class Family { private ArrayList<Person> myMembers; public Family() { myMembers = new ArrayList<Person>(); } public void addMember( Person p ) { myMembers.add( p ); } public ArrayList<Person> getMembers() { return myMembers; } }5. Which of the following statements assigns a Person object to the variable p?I. Person p = Person( "fred", 8 );II. Person p = new Person( "fred", 8 );III. Person p( "fred", 8 );A. I onlyB. II onlyC. III onlyD. I and II onlyE. I, II and III6. What is the output from the following code?Person f; f = new Person( "Thomas", 2 ); int i = 0; while ( i < 5 ) { f.birthday(); i++; } System.out.println( f.getAge() ); A. 0B. 2C. 5D. 7E. None of the above — an exception is thrown.

    提问者:tj_zhangmin

    发布于2010-08-12

共1个回答
  • gooorvdru 丨Lv 2
    BCDBD
    +1 2010-08-12 举报
热门人气推荐
免责声明:问答内容均来源于互联网用户,房天下对其内容不负责任,如有版权或其他问题可以联系房天下进行删除。