Final Exam. Programming Assignment 3. University of British Columbia CPSC 111, Intro to Computation Alan J. Hu. Readings

Similar documents
Final Exam. Programming Assignment 3. University of British Columbia CPSC 111, Intro to Computation Alan J. Hu. Readings

Survey #2. Programming Assignment 3. Final Exam. University of British Columbia CPSC 111, Intro to Computation Alan J. Hu.

Survey #2. Programming Assignment 3. University of British Columbia CPSC 111, Intro to Computation Alan J. Hu. Readings

Survey #2. Variable Scope. University of British Columbia CPSC 111, Intro to Computation Alan J. Hu. Readings. Scope Static.

Survey #2. Teen Talk Barbie TM Reloaded. University of British Columbia CPSC 111, Intro to Computation Alan J. Hu Partially Filled Arrays ArrayLists

Midterms Save the Dates!

Survey #2. Assignment #3. University of British Columbia CPSC 111, Intro to Computation Alan J. Hu. Readings. Static Interface Types.

Midterms Save the Dates!

Midterms Save the Dates!

Midterms Save the Dates!

Midterms Save the Dates!

Last Time. University of British Columbia CPSC 111, Intro to Computation Alan J. Hu. Readings

Survey #3. Final Exam. Today is totally optional! University of British Columbia CPSC 111, Intro to Computation Alan J. Hu. Readings.

Last Week: Organizing Data. Last Week: Parallel Arrays. University of British Columbia CPSC 111, Intro to Computation Alan J. Hu.

University of British Columbia CPSC 111, Intro to Computation Jan-Apr 2006 Tamara Munzner

Inheritance and Interfaces

University of British Columbia CPSC 111, Intro to Computation Jan-Apr 2006 Tamara Munzner

CS 112 Introduction to Computing II. Wayne Snyder Computer Science Department Boston University

CPSC 324 Topics in Java Programming

Midterms Save the Dates!

Spring 2003 Instructor: Dr. Shahadat Hossain. Administrative Matters Course Information Introduction to Programming Techniques

Midterms Save the Dates!

Agenda CS121/IS223. Reminder. Object Declaration, Creation, Assignment. What is Going On? Variables in Java

Tutorial 2 Today we will have a quick introduction to ArgoUML and how to use it, as well as look at some examples of class diagrams.

CONTENTS: What Is Programming? How a Computer Works Programming Languages Java Basics. COMP-202 Unit 1: Introduction

Using Classes and Objects. Lecture 7. Midterms Save the Dates! Extra Credit Survey

CS121/IS223. Object Reference Variables. Dr Olly Gotel

CS 251 Intermediate Programming Inheritance


Announcements. 1. Forms to return today after class:

Lecture 2: Java & Javadoc

Arrays Classes & Methods, Inheritance

CE221 Programming in C++ Part 1 Introduction

Programming Languages and Techniques (CIS120)

Bjarne Stroustrup. creator of C++

Physics 2660: Fundamentals of Scientific Computing. Lecture 7 Instructor: Prof. Chris Neu

QUIZ. How could we disable the automatic creation of copyconstructors

CS/IT 114 Introduction to Java, Part 1 FALL 2016 CLASS 8: SEP. 29TH INSTRUCTOR: JIAYIN WANG

} Evaluate the following expressions: 1. int x = 5 / 2 + 2; 2. int x = / 2; 3. int x = 5 / ; 4. double x = 5 / 2.

COSC 121: Computer Programming II. Dr. Bowen Hui University of Bri?sh Columbia Okanagan

Software and Programming 1

Midterms Save the Dates!

CS 177 Recitation. Week 1 Intro to Java

COMP-202: Foundations of Programming. Lecture 2: Java basics and our first Java program! Jackie Cheung, Winter 2015

Introduction to Computation and Problem Solving

CS125 : Introduction to Computer Science. Lecture Notes #6 Compound Statements, Scope, and Advanced Conditionals

Principles of Software Construction: Objects, Design and Concurrency. Mutability and Java Potpourri. toad Fall 2013

Inheritance and Polymorphism

CSE 113 A. Announcements - Lab

PeerWise Study. Midterms Save the Dates! University of British Columbia CPSC 111, Intro to Computation Alan J. Hu. Constants Using Classes and Objects

CSC207 Week 3. Larry Zhang

Classes, objects, methods and properties

CPSC Tutorial 4

CS 170 Java Programming 1. Week 12: Creating Your Own Types

Project #1 rev 2 Computer Science 2334 Fall 2013 This project is individual work. Each student must complete this assignment independently.

1.00 Lecture 2. What s an IDE?

Lecture 3. COMP1006/1406 (the Java course) Summer M. Jason Hinek Carleton University

University of British Columbia CPSC 111, Intro to Computation 2009W2: Jan-Apr 2010 Tamara Munzner

CS/IT 114 Introduction to Java, Part 1 FALL 2016 CLASS 9: OCT. 4TH INSTRUCTOR: JIAYIN WANG

Lecture 6. COMP1006/1406 (the OOP course) Summer M. Jason Hinek Carleton University

CS 112 Introduction to Computing II. Wayne Snyder Computer Science Department Boston University

Smalltalk: developed at Xerox Palo Alto Research Center by the Learning Research Group in the 1970 s (Smalltalk-72, Smalltalk-76, Smalltalk-80)

Reviewing for the Midterm Covers chapters 1 to 5, 7 to 9. Instructor: Scott Kristjanson CMPT 125/125 SFU Burnaby, Fall 2013

Inf1-OOP. OOP Exam Review. Perdita Stevens, adapting earlier version by Ewan Klein. March 16, School of Informatics

Every language has its own scoping rules. For example, what is the scope of variable j in this Java program?

Lecture 02, Fall 2018 Friday September 7

CSCI-142 Exam 1 Review September 25, 2016 Presented by the RIT Computer Science Community

Basic Keywords Practice Session

CS/ENGRD 2110 FALL Lecture 5: Local vars; Inside-out rule; constructors

! labs last week. ! still time to work through lab 7 (midterm correction) ! can earn back up to 5 out of 70 points

CIS 110: Introduction to Computer Programming. Lecture 2 Decomposition and Static Methods ( 1.4)

Java Basics. Object Orientated Programming in Java. Benjamin Kenwright

Fall 2017 CISC124 9/16/2017

COP 3330 Final Exam Review

QUIZ. How could we disable the automatic creation of copyconstructors

HAS-A Relationship. Association is a relationship where all objects have their own lifecycle and there is no owner.

Object Oriented Programming. Week 1 Part 1 An introduction to Java, Objects and JUnit

5.6.1 The Special Variable this

Java Puzzle Ball Nick Ristuccia

Physics 2660: Fundamentals of Scientific Computing. Lecture 3 Instructor: Prof. Chris Neu

School of Computer Science CPS109 Course Notes 6 Alexander Ferworn Updated Fall 15. CPS109 Course Notes 6. Alexander Ferworn

CSCI 201L Final Written SOLUTION. 13% of course grade

Example: Fibonacci Numbers

Project 1 Computer Science 2334 Spring 2016 This project is individual work. Each student must complete this assignment independently.

Inheritance, Polymorphism, and Interfaces

Software Practice 1 Basic Grammar

CS/IT 114 Introduction to Java, Part 1 FALL 2016 CLASS 3: SEP. 13TH INSTRUCTOR: JIAYIN WANG

COMPUTER SCIENCE DEPARTMENT PICNIC. Operations. Push the power button and hold. Once the light begins blinking, enter the room code

Last Time. University of British Columbia CPSC 111, Intro to Computation Alan J. Hu. Readings

Inheritance and Polymorphism. CS180 Fall 2007

Tutorials. Tutorial every Friday at 11:30 AM in Toldo 204 * discuss the next lab assignment

Inf1-OP. Inf1-OP Exam Review. Timothy Hospedales, adapting earlier version by Perdita Stevens and Ewan Klein. March 20, School of Informatics

Decisions, Decisions, Decisions. GEEN163 Introduction to Computer Programming

Note: This is a miniassignment and the grading is automated. If you do not submit it correctly, you will receive at most half credit.

Lecture 5. Defining Functions

A final method is a method which cannot be overridden by subclasses. A class that is declared final cannot be inherited.

Classes, Objects, and OOP in Java. June 16, 2017

CSCE 156 Computer Science II

COMP-202: Foundations of Programming. Lecture 2: Java basics and our first Java program! Jackie Cheung, Winter 2016

Midterms Save the Dates!

Transcription:

University of British Columbia CPSC 111, Intro to Computation Alan J. Hu Interfaces vs. Inheritance Abstract Classes Inner Classes Readings This Week: No new readings. Consolidate! (Reminder: Readings are absolutely vital for learning this stuff!) Lecture 33 Labs and Tutorials This Week: Lab #10 111 TAs in Learning Centre might mark labs more details coming (121 TAs won t do this marking, so check the posted schedule on the Learning Centre door.) Final Exam Wednesday, April 15, 7pm in SRC A This wasn t a good room last year, but we re stuck with the date, time, and room UBC assigns. Note: You are allowed to do scratch work on the exam paper! (But write your answer where indicated if the problem tells you to.) Programming Assignment 3 Assignment 3 is up on WebCT! Click on the Assignments icon. Assigned Sunday evening sorry for delay! Due at NOON, April 6 (Monday), via electronic hand in. Tips: There is some Eclipse setup. Set-up ASAP! Work in pairs. Some conceptual stuff. Think carefully before coding. If concepts right, the coding is much much easier. Learning Goals By the end of today you will be able to List similarities and differences between s and inheritance. Create abstract es and extend abstract es. Write code that uses inner es. 1

We learned these as completely separate concepts: An is a contract, specifying some methods that must be implemented by any that claims to implement the. A super is a from which other es can inherit methods and instance fields, so we can reuse the super s implementation. But they have similarities Both allow creating different, new es that share some of the same methods, e.g. Double and both implement, so they both have int compareto() Swimmer and Crawler both inherit from Animal, so they have e.g., changeimage() But they have similarities Both allow declaring references that can point to different kinds of objects, e.g., x; x = new Double(3.14); x = new ( Alan ); Person y; y = new ( Alan,0.0); y = new Celebrity( Paris Hilton ); But they have similarities Therefore, both allow polymorphism, e.g., x;... if (x.compareto()) Animal y;... y.advanceonetimestep(); But they have similarities They even have similar UML: They have differences, too Java allows implementing multiple s Feedable OK! 2

They have differences, too Java does NOT allow multiple inheritance Marsupial (Java does allow one inheritance plus multiple s.) Feedable OK! An provides no implementations. Everything in a (super) is implemented. To implement, a must implement everything. Subes automatically inherit super implementation. Can optionally override. Questions Therefore: You cannot create objects of an type (only references). You can create objects of the (super) type. (You can create references, too.) 3

An provides no implementations. Everything in a (super) is implemented. Wouldn t it be cool to have something in-between? Abstract Classes The es we have written so far are called es. Abstract es in Java provide a blend of the concepts of s and inheritance: Some (from none to all) methods are left unimplemented. These are called. Instances fields and implemented methods are also allowed. Sub must implement (in order to become ). Sub inherits or overrides other stuff. Abstract Class Syntax To create an abstract, just add the abstract keyword: public abstract Foo { Abstract Method Syntax Inside an abstract, you are allowed to declare : Just add the abstract keyword. And put a semicolon instead of a body. public abstract Foo { public abstract void display(); Abstract Classes vs. Interfaces/Inheritance An abstract with no is basically a normal,. (But Java still thinks it s an abstract!) An abstract with all is basically like an. (But Java still thinks it s an abstract!) An abstract with some abstract methods is somewhere in-between. The Interface-Class Spectrum abstract w/ no 4

The Interface-Class Spectrum The Interface-Class Spectrum abstract w/ no Can create objects only of es You can implement multiple s. abstract w/ no Questions Inner Classes So far, es are always in a file by themselves (with the same name as the ). Sometimes, we just want a simple little for something. It s a pain to have a separate file. We can declare es inside another: method Example: Inner Class in a Method public static void main(string[] args) { Foo { private int x; public int getx() { return x; Foo is available only inside main. Foo can access surrounding vars with restrictions. Inner Class Scope Remember the general principle that you can see out through curly braces, but not in. Therefore, inner es should be able to see variables declared around them: Instance variable in same Local variables if declared inside a method However, object of inner can outlive the code where it was created! Access is to instance variables of object that created inner. Access only to final local variables. (These can be references to mutable objects, though.) 5