1.Assume you initialize a Java ArrayList as follows: ArrayList myList = new ArrayList(); What will hap

Business, Finance, Economics, Accounting, Operations Management, Computer Science, Electrical Engineering, Mechanical Engineering, Civil Engineering, Chemical Engineering, Algebra, Precalculus, Statistics and Probabilty, Advanced Math, Physics, Chemistry, Biology, Nursing, Psychology, Certifications, Tests, Prep, and more.
Post Reply
answerhappygod
Site Admin
Posts: 899603
Joined: Mon Aug 02, 2021 8:13 am

1.Assume you initialize a Java ArrayList as follows: ArrayList myList = new ArrayList(); What will hap

Post by answerhappygod »

1.Assume you initialize a Java ArrayList as follows:
ArrayList<Integer> myList = new
ArrayList<Integer>();
What will happen if you then call
myList.get(0)
a.The call will return the value 0
b.The call will return the value null
c. The call will return the value -1 to indicate that the
index is out of bounds
d.Choice 4 of 4:The call will throw
an IndexOutOfBoundsException
2. The ArrayList class in Java has the following
declaration:
Which of the following statements is true? Select all that
apply.
a.List<Integer> ref = new
ArrayList<Integer>(); has a compiler error
because List can't point to
an ArrayList object
b. List<Object> ref = new
ArrayList<Integer>(); has a compiler error
as List<Object> is not same
as ArrayList<Integer>
c. If we have an ArrayList<Object>, we can put
a String object into location 0 and an Integer object to
location 1. It is because any class in Java is
an Object (extends from Object) by default.
d. ArrayList is a List, so it has all the methods
specified in List
3.
Consider the following generic class declaration:
Which of the following would NOT be allowed in
this class's non-static methods? Select all that apply.
a.Creating a variable of type E (i.e. E
myVar;)
b. Creating an object of type E (i.e. new
E();)
c.Creating an array with elements of
type E (i.e. new E[100];)
d.Creating an ArrayList to store elements of
type E (i.e. new ArrayList<E>());
4.An arraylist myAL looks like this
{4,2,1,9,null,null}
What is the size and capacity of myAL?
a.Size=4, Capacity=6
b.Size=6, Capacity=4
c.Neither of the above
Join a community of subject matter experts. Register for FREE to view solutions, replies, and use search function. Request answer by replying!
Post Reply