Question: Question 9 Assume that the following code has been executed (same for Questions 7 thru 10) : ArrayList plot = new ArrayList (); Point p
Question 9
Assume that the following code has been executed (same for Questions 7 thru 10):
ArrayListplot = new ArrayList (); Point p = new Point( 12, 16 ); plot.add( p ); plot.add( new Point( 0, 0 ) ); plot.add( new Point( 4, 8 ) ); plot.add( 2, new Point( 5, 10 ) ); p = plot.get( 0 ); p = plot.remove( 1 ); plot.add( new Point( -5, 5 ) );
Which Point is returned by the following expression? plot.get( 2 )
| 0,0 |
| 12,16 |
| 4,8 |
| -5,5 |
| None -- the statement throws a runtime exception |
Question 10
Assume that the following code has been executed (same for Questions 7 thru 10):
ArrayListplot = new ArrayList (); Point p = new Point( 12, 16 ); plot.add( p ); plot.add( new Point( 0, 0 ) ); plot.add( new Point( 4, 8 ) ); plot.add( 2, new Point( 5, 10 ) ); p = plot.get( 0 ); p = plot.remove( 1 ); plot.add( new Point( -5, 5 ) );
Which Point is returned by the following expression? plot.get( 5 )
| The value null is returned |
| 5,10 |
| -5,5 |
| 4,8 |
| None -- the statement throws a runtime exception |
Question 11
Assume that the following code has been executed (same for Questions 11 thru 14):
ArrayListnums = new ArrayList (); nums.add( 12 ); nums.add( 32 ); nums.add( 15 ); nums.add( 2, 11 ); nums.add( 6 ); int s = nums.size() ; int sum = 0; Iterator it = nums.iterator(); while( it.hasNext() ) { int n = it.next(); if ( n % 2 == 1 ) sum = sum + n; } nums.remove( 0 );
What is the value of the variable 's'?
| 6 |
| 4 |
| 5 |
| 2 |
| 7 |
Question 12
Assume that the following code has been executed (same for Questions 11 thru 14):
ArrayListnums = new ArrayList (); nums.add( 12 ); nums.add( 32 ); nums.add( 15 ); nums.add( 2, 11 ); nums.add( 6 ); int s = nums.size(); int sum = 0; Iterator it = nums.iterator(); while( it.hasNext() ) { int n = it.next(); if ( n % 2 == 1 ) sum = sum + n; } nums.remove( 0 );
What is the value of the variable 'sum'?
| 76 |
| 78 |
| 26 |
| 50 |
| 15 |
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
