Presentation is loading. Please wait.

Presentation is loading. Please wait.

Clicker quiz 10/29/13 CSE 1102 Fall 2013. __________ is visible to code in the inner class (at ????, say): A.All protected methods and protected instance.

Similar presentations


Presentation on theme: "Clicker quiz 10/29/13 CSE 1102 Fall 2013. __________ is visible to code in the inner class (at ????, say): A.All protected methods and protected instance."— Presentation transcript:

1 Clicker quiz 10/29/13 CSE 1102 Fall 2013

2 __________ is visible to code in the inner class (at ????, say): A.All protected methods and protected instance variables of the outer class B.All public methods and public instance variables of the outer class C.All methods and all public instance variables of the outer class D.All methods and instance variables of the outer class. E.None of the above is true Suppose I define an inner class, as was done in MoveTimer. The code in the inner class can access: 1.public class Outer extends SomeClass implements SomeInterface{ 2.... 3. private class Inner extends AnotherClass { 4. ???? 5. } 6.}

3 Which of the following is a limitation of Java arrays? A.They can only hold primitive types. B.They can only hold objects C.Once an element is added to an array, that element cannot be modified D.Their length must be computed E.They cannot change size.

4 A. super(); B. _balls.setLength(numberOfBalls); C. _balls = new Ball[numberOfBalls]; D. _balls.length = numberOfBalls; E. B, C, and D all work. 1.public BallPanel extends javax.swing.Panel { 2.private Ball[] _balls; 3.public BallPanel(int numberOfBalls){ 4.?????? 5.for (int i=0;i<_balls.length;i++) 6._balls[i] = new Ball(); 7.} In line 4, we need to do the following or there will be an error in line 5:

5 A. 0, numberOfBalls B. numberOfBalls, numberOfBalls C. i, numberOfBalls D. 0, numberOfBalls – 1 E. _balls.length is undefined 1.public BallPanel extends javax.swing.Panel { 2.private Ball[] _balls; 3.public BallPanel(int numberOfBalls){ 4._balls = new Ball[numberOfBalls]; 5.for (int i=0;i<_balls.length;i++) 6._balls[i] = new Ball(); 7.} What is the value of _balls.length immediately after lines 4 and 6 (respectively) ?

6 Clicker questions 10/29/13 CSE 1102 Fall 2013

7 What does the following program segment print, or what error does it cause? double[] myArray = new double[10]; System.out.println(myArray[0]); A) -1.0 B) 0.0 C) Compile time error: array not initialized D) Runtime error: NullPointerException E) Runtime error: ArrayIndexOutOfBoundsException

8 What does the following program segment print, or what error does it cause? double[] myArray = new double[10]; System.out.println(myArray[10]); A) -1.0 B) 0.0 C) Compile time error: array not initialized D) Runtime error: NullPointerException E) Runtime error: ArrayIndexOutOfBoundsException

9 What does the following program segment print, or what error does it cause? double[] myArray; System.out.println(myArray[0]); A) -1.0 B) 0.0 C) Compile time error: array not initialized D) Runtime error: NullPointerException E) Runtime error: ArrayIndexOutOfBoundsException

10 After I have constructed a BallPanel, which of the following Java statements would work (if executed in some method of BallPanel)? Assume Ball has a public getColor() method. A._balls[20] = new Ball(); B._balls[10].getColor(); C._balls[0] = _balls[15]; D. Both A and C work E. Both B and C work 1.public BallPanel extends javax.swing.Panel { 2. private Ball[] _balls; 3.public BallPanel(){ 4. _balls = new Ball[20]; 5.for (int i=0;i<10;i++) 6._balls[i] = new Ball(); 7.}

11 After line 10, what are the values of _balls.length and _moreBalls.size() respectively? A.0, 0 B.10, 10 C.20, 20 D.10, 20 E.20, 10 1.public BallPanel extends javax.swing.Panel { 2. private Ball[] _balls; 3.private ArrayList _moreBalls; 4.public BallPanel(){ 5. _balls = new Ball[20]; 6. _moreBalls = new ArrayList (); 7.for (int i=0;i<10;i++) { 8._balls[i] = new Ball(); 9. _moreBalls.add(_balls[i]); 10. } 11.}

12 A. The array _balls is unchanged B. The first element of _balls is a new Ball constructed using new Ball(Color.pink); not the same as the first element of _moreBalls; C. _balls[0] == _moreBalls[0]; D. 0, numberOfBalls – 1 E. _balls.length is undefined 1.public BallPanel extends javax.swing.Panel { 2.private Ball[] _balls; 3. private Ball[] _moreBalls; 4.public BallPanel(int numberOfBalls){ 5._balls = new Ball[numberOfBalls]; 6.for (int i=0;i<_balls.length;i++) 7._balls[i] = new Ball(); 8. _moreBalls = _balls; 9.} Which of the following statements is true, after executing BallPanel myPanel = new BallPanel(5); _moreBalls[0] = new Ball(Color.pink); ?

13 A. The array _balls is unchanged B. The elements of temp are copies of the elements of _balls C. _balls.length == 20 D. _balls.length == 10; E. None of the above 1.public BallPanel extends javax.swing.Panel { 2.private Ball[] _balls; 3.public BallPanel(int numberOfBalls){ 4._balls = new Ball[numberOfBalls]; 5.for (int i=0;i<_balls.length;i++) 6._balls[i] = new Ball(); 7.} 8. public void ballCopy () { 9. Ball[] temp = new Ball[2 * _balls.length]; 10. for (int j=0; j< _balls.length; j++0) 11. _temp[j] = _balls[j]; 12. _balls = temp; }} After executing BallPanel myPanel = new BallPanel(10); _myPanel.ballCopy();

14 A. 0, numberOfBalls B. numberOfBalls, numberOfBalls C. i, numberOfBalls D. 0, numberOfBalls – 1 E. _moreBalls.size() is undefined 1.public BallPanel extends javax.swing.Panel { 2.private ArrayList _moreBalls; 3.public BallPanel(int numberOfBalls){ 4. _moreBalls = new ArrayList (); 5.for (int i=0;i<numberOfBalls;i++) 6._moreBalls.add(new Ball()); 7.} What is the value of _moreBalls.size() immediately after lines 4 and 6 (respectively)?

15 Remember this code 1234512345 67896789

16 A. 4 1 2 6 3 4 B. 8 1 2 6 4 8 C. 1 2 3 4 5 1 D. 8 9 7 2 6 8 E. 4 3 5 2 6 4 The decoded value of the above message is

17 Remember this (same) code 1 2 3 4 5 6 7 8 9

18 A. 4 1 2 6 3 4 B. 8 1 2 6 4 8 C. 1 2 3 4 5 1 D. 8 9 7 2 6 8 E. 4 3 5 2 6 4 The decoded value of the above message is


Download ppt "Clicker quiz 10/29/13 CSE 1102 Fall 2013. __________ is visible to code in the inner class (at ????, say): A.All protected methods and protected instance."

Similar presentations


Ads by Google