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.

Slides:



Advertisements
Similar presentations
EXAMPLES (Arrays). Example Many engineering and scientific applications represent data as a 2-dimensional grid of values; say brightness of pixels in.
Advertisements

1.A computer game is an example of A.system software; B.a compiler; C.application software; D.hardware; E.none of the above. 2.JVM stands for: A.Java Virtual.
COSC 2006 Data Structures I Instructor: S. Xu URL:
Computer Science 209 Software Development Equality and Comparisons.
METHOD OVERRIDING Sub class can override the methods defined by the super class. Overridden Methods in the sub classes should have same name, same signature.
Composition CMSC 202. Code Reuse Effective software development relies on reusing existing code. Code reuse must be more than just copying code and changing.
Written by: Dr. JJ Shepherd
Arrays and ArrayLists Ananda Gunawardena. Introduction Array is a useful and powerful aggregate data structure presence in modern programming languages.
CIT 590 Intro to Programming Java lecture 4. Agenda Types Collections – Arrays, ArrayLists, HashMaps Variable scoping Access modifiers – public, private,
Road Map Introduction to object oriented programming. Classes
Loops Notes adapted from Dr. Flores. It repeats a set of statements while a condition is true. while (condition) { execute these statements; } “while”
©The McGraw-Hill Companies, Inc. Permission required for reproduction or display. 4 th Ed Chapter N - 1 Polymorphism.
18-Jun-15 Arrays. 2 A problem with simple variables One variable holds one value The value may change over time, but at any given time, a variable holds.
© The McGraw-Hill Companies, 2006 Chapter 5 Arrays.
1 Generics and Using a Collection Generics / Parameterized Classes Using a Collection Customizing a Collection using Inheritance Inner Classes Use of Exceptions.
Arrays. Example Write a program to keep track of all students’ scores on exam 1. Need a list of everyone’s score Declare 14 double variables? What about.
26-Jun-15 Arrays. 2 A problem with simple variables One variable holds one value The value may change over time, but at any given time, a variable holds.
Inheritance and Polymorphism Recitation – 10/(16,17)/2008 CS 180 Department of Computer Science, Purdue University.
CS 106 Introduction to Computer Science I 03 / 08 / 2010 Instructor: Michael Eckmann.
Arrays. A problem with simple variables One variable holds one value –The value may change over time, but at any given time, a variable holds a single.
Arrays, Loops weeks 4-6 (change from syllabus for week 6) Chapter 4.
Arrays. A problem with simple variables One variable holds one value –The value may change over time, but at any given time, a variable holds a single.
Chapter 6Java: an Introduction to Computer Science & Programming - Walter Savitch 1 l Array Basics l Arrays in Classes and Methods l Programming with Arrays.
Inheritance using Java
Lec 19 Array Intro. Agenda Arrays—what are they Declaring Arrays Constructing Arrays Accessing Array cells.
By Nicholas Policelli An Introduction to Java. Basic Program Structure public class ClassName { public static void main(String[] args) { program statements.
Java Quiz Bowl A fun review of the Java you should know from CMPT 201 If you don’t know the answers - this week is for you to study up!
5-Aug-2002cse Arrays © 2002 University of Washington1 Arrays CSE 142, Summer 2002 Computer Programming 1
Copyright © 2002, Systems and Computer Engineering, Carleton University a-JavaReview.ppt * Object-Oriented Software Development Unit.
Arrays and ArrayLists in Java L. Kedigh. Array Characteristics List of values. A list of values where every member is of the same type. Each member in.
1 © 2002, Cisco Systems, Inc. All rights reserved. Arrays Chapter 7.
Working with arrays (we will use an array of double as example)
M180: Data Structures & Algorithms in Java Arrays in Java Arab Open University 1.
1 CISC181 Introduction to Computer Science Dr. McCoy Lecture 7 Clicker Questions September 22, 2009.
Static Methods. 2 Objectives Look at how to build static (class) methods Study use of methods calling, parameters, returning values Contrast reference.
Java Basics.  To checkout, use: svn co scb07f12/UTORid  Before starting coding always use: svn update.
Chapter 6 Introduction to Defining Classes. Objectives: Design and implement a simple class from user requirements. Organize a program in terms of a view.
BEGINNING PROGRAMMING.  Literally – giving instructions to a computer so that it does what you want  Practically – using a programming language (such.
Peter Andreae Computer Science Victoria University of Wellington Copyright: Peter Andreae, Victoria University of Wellington Types and Interfaces COMP.
Clicker questions 10/24/13 CSE 1102 Fall θ (x,y) (0,0) What is the relationship between θ and (x,y) ? A.y = mx + b B.θ = x 2 + y 2 C.tan(θ) = x/y;
Chapter 5 Objects and Classes Inheritance. Solution Assignments 3 & 4 Review in class…..
CSC 212 Object-Oriented Programming and Java Part 2.
Java Class Structure. Class Structure package declaration import statements class declaration class (static) variable declarations* instance variable.
Chapter 8 Class Inheritance and Interfaces F Superclasses and Subclasses  Keywords: super F Overriding methods  The Object Class  Modifiers: protected,
Types, Implementing, Extending, Interfaces, Superclasses, Subclasses, Casting, and Access Modifiers.
Peter Andreae Computer Science Victoria University of Wellington Copyright: Peter Andreae, Victoria University of Wellington Types and Interfaces COMP.
Composition When one class contains an instance variable whose type is another class, this is called composition. Instead of inheritance, which is based.
1 CSC 2053 New from AutoBoxing 3 Before J2SE 5.0, working with primitive types required the repetitive work of converting between the primitive.
Arrays and ArrayLists Topic 6. One Dimensional Arrays Homogeneous – all of the same type Contiguous – all elements are stored sequentially in memory For.
Clicker quiz 10/8/13 CSE 1102 Fall 2013 (E-30 reminder!)
Quick Review of OOP Constructs Classes:  Data types for structured data and behavior  fields and methods Objects:  Variables whose data type is a class.
Written by: Dr. JJ Shepherd
AP Java Ch. 4 Review Question 1  Java methods can return only primitive types (int, double, boolean, etc).
Quick topix 11/7/13 CSE 1102 Fall previous statement Execute rest of program Is true? yes no This flowchart illustrates the logic of a _________.
OOP Basics Classes & Methods (c) IDMS/SQL News
Clicker quiz 9/17/13 CSE 1102 Fall // In Blob: public void mousePressed(MouseEvent e){ this.setFillColor(java.awt.Color.blue); } // in WinkingBlob.
Quick topix 11/7/13 CSE 1102 Fall previous statement Execute rest of program Is true? yes no This flowchart illustrates the logic of a _________.
Throw, Throws & Try-Catch Statements Explanations and Pictures from: Reference:
Exceptions and Error Handling. Exceptions Errors that occur during program execution We should try to ‘gracefully’ deal with the error Not like this.
Winter 2006CISC121 - Prof. McLeod1 Last Time Reviewed class structure: –attributes –methods –(inner classes) Looked at the effects of the modifiers: –public.
Last Revision. Question1 Novice Java programmers often write code similar to, class C { public int x;... }... C[] a = new C[10]; for(int i = 0; i < a.length;
Advanced Programming Practice Questions Advanced Programming. All slides copyright: Chetan Arora.
9.1 CLASS (STATIC) VARIABLES AND METHODS Defining classes is only one aspect of object-oriented programming. The real power of object-oriented programming.
LESSON 8: INTRODUCTION TO ARRAYS. Lesson 8: Introduction To Arrays Objectives: Write programs that handle collections of similar items. Declare array.
Clicker quiz 10/22/13 CSE 1102 Fall 2013.
Inner Classes.
Inheritance and Polymorphism
Clicker quiz 10/15/13 CSE 1102 Fall 2013.
Review of Previous Lesson
Review: libraries and packages
Presentation transcript:

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 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{ private class Inner extends AnotherClass { 4. ???? 5. } 6.}

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.

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:

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) ?

Clicker questions 10/29/13 CSE 1102 Fall 2013

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

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

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

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.}

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.}

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); ?

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();

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)?

Remember this code

A B C D E The decoded value of the above message is

Remember this (same) code

A B C D E The decoded value of the above message is