Logistics. Final Exam on Friday at 3pm in CHEM 102

Similar documents
Everything You Ever Wanted To Know About Java O-O. 7-Dec-15

What is a class? Object Oriented Programming. What is a class? Classes. A class is primarily a description of objects, or instances, of that class

cannot be used directly by the class However, a static method can create (or be given) objects, and can send messages to them

Object Oriented Programming

Argument Passing All primitive data types (int etc.) are passed by value and all reference types (arrays, strings, objects) are used through refs.

Advanced Programming - JAVA Lecture 4 OOP Concepts in JAVA PART II

Rules and syntax for inheritance. The boring stuff

OVERRIDING. 7/11/2015 Budditha Hettige 82

Self-review Questions

Java Inheritance. Written by John Bell for CS 342, Spring Based on chapter 6 of Learning Java by Niemeyer & Leuck, and other sources.

And Even More and More C++ Fundamentals of Computer Science

Inheritance. Lecture 11 COP 3252 Summer May 25, 2017

1B1b Inheritance. Inheritance. Agenda. Subclass and Superclass. Superclass. Generalisation & Specialisation. Shapes and Squares. 1B1b Lecture Slides

Java for Non Majors. Final Study Guide. April 26, You will have an opportunity to earn 20 extra credit points.

Chapter 14 Abstract Classes and Interfaces

5.6.1 The Special Variable this

Programming II (CS300)

Prelim 1 Solutions. CS 2110, March 10, 2015, 5:30 PM Total Question True False. Loop Invariants Max Score Grader

Practice for Chapter 11

Software Paradigms (Lesson 3) Object-Oriented Paradigm (2)

Building custom components IAT351

CS 251 Intermediate Programming Inheritance

Chapter 5 Object-Oriented Programming

Basic Principles of OO. Example: Ice/Water Dispenser. Systems Thinking. Interfaces: Describing Behavior. People's Roles wrt Systems

Java Object Oriented Design. CSC207 Fall 2014

INHERITANCE. Spring 2019

COP 3330 Final Exam Review

Review: Object Diagrams for Inheritance. Type Conformance. Inheritance Structures. Car. Vehicle. Truck. Vehicle. conforms to Object

CO Java SE 8: Fundamentals

Object Oriented Programming Part II of II. Steve Ryder Session 8352 JSR Systems (JSR)

CSE331 Winter 2014, Final Examination March 17, 2014 Please do not turn the page until 8:30. Rules:

Programming II (CS300)

OBJECT ORİENTATİON ENCAPSULATİON

Inheritance & Polymorphism

Inheritance and Interfaces

CS100J, Fall 2003 Preparing for Prelim 1: Monday, 29 Sept., 7:30 9:00PM

COE318 Lecture Notes Week 9 (Week of Oct 29, 2012)

Object Fundamentals Part Three. Kenneth M. Anderson University of Colorado, Boulder CSCI 4448/6448 Lecture 4 09/06/2007

Chapter 12. OOP: Creating Object-Oriented Programs The McGraw-Hill Companies, Inc. All rights reserved. McGraw-Hill

Lesson 10A OOP Fundamentals. By John B. Owen All rights reserved 2011, revised 2014

Inheritance and Polymorphism. CS180 Fall 2007

COE318 Lecture Notes Week 8 (Oct 24, 2011)

Agenda. Objects and classes Encapsulation and information hiding Documentation Packages

Polymorphism. return a.doublevalue() + b.doublevalue();

Inheritance (Outsource: )

Lecture Contents CS313D: ADVANCED PROGRAMMING LANGUAGE. What is Inheritance?

Super-Classes and sub-classes

Lab 2: Object-Oriented Design 12:00 PM, Jan 31, 2018

Chapter 6 Introduction to Defining Classes

INHERITANCE AND EXTENDING CLASSES

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

Chapter 10 Classes Continued. Fundamentals of Java

Foundations of object orientation

CS111: PROGRAMMING LANGUAGE II

Introduction to Programming Using Java (98-388)

More Relationships Between Classes

CS Internet programming Unit- I Part - A 1 Define Java. 2. What is a Class? 3. What is an Object? 4. What is an Instance?

CS313D: ADVANCED PROGRAMMING LANGUAGE

AP COMPUTER SCIENCE JAVA CONCEPTS IV: RESERVED WORDS

Everything is an object. Almost, but all objects are of type Object!

Logistics. Homework 9 due tomorrow Will post Homework 10 over the next few days. No class/recitation on Wednesday

CS313D: ADVANCED PROGRAMMING LANGUAGE

C a; C b; C e; int c;

Core Java - SCJP. Q2Technologies, Rajajinagar. Course content

Java Magistère BFA

Weiss Chapter 1 terminology (parenthesized numbers are page numbers)

UMBC CMSC 331 Final Exam

Chapter 4 Defining Classes I

Overview. Lecture 7: Inheritance and GUIs. Inheritance. Example 9/30/2008

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

Microsoft Visual Basic 2005: Reloaded

Subclass Gist Example: Chess Super Keyword Shadowing Overriding Why? L10 - Polymorphism and Abstract Classes The Four Principles of Object Oriented

COMP200 INTERFACES. OOP using Java, from slides by Shayan Javed

CMSC 132: Object-Oriented Programming II

Introduction to C++ Introduction to C++ Dr Alex Martin 2013 Slide 1

CS Programming I: Inheritance

Class, Variable, Constructor, Object, Method Questions

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

CSE 331 Final Exam 3/16/15 Sample Solution

Polymorphism and Interfaces. CGS 3416 Spring 2018

More on Objects in JAVA TM

CSSE 220 Day 15. Inheritance. Check out DiscountSubclasses from SVN

CS111: PROGRAMMING LANGUAGE II

Declarations and Access Control SCJP tips

Inheritance and Encapsulation. Amit Gupta

Midterm Exam CS 251, Intermediate Programming March 12, 2014

CMSC 132: Object-Oriented Programming II

Inheritance and Polymorphism in Java

Object Oriented Programming. Java-Lecture 11 Polymorphism

Exam Duration: 2hrs and 30min Software Design

Object Oriented Programming: In this course we began an introduction to programming from an object-oriented approach.

QUESTIONS FOR AVERAGE BLOOMERS

Inheritance and Polymorphism

Inheritance (Part 5) Odds and ends

Topic 5 Polymorphism. " Inheritance is new code that reuses old code. Polymorphism is old code that reuses new code.

COMP 401 Spring 2014 Midterm 1

CS-202 Introduction to Object Oriented Programming

Abstract Classes and Interfaces

Java for Non Majors Spring 2018

CSE 331 Software Design and Implementation. Lecture 14 Generics 2

Transcription:

Java Review

Logistics Final Exam on Friday at 3pm in CHEM 102

What is a class? A class is primarily a description of objects, or instances, of that class A class contains one or more constructors to create objects A class is a type The type of an object is the class that created it But a class can also contain information about itself Anything declared static belongs to the class itself Static variables contain information about the class, not about instances of the class Static methods are executed by the class, not by instances of the class Anything not declared static is not part of the class, and cannot be used directly by the class

Why inheritance? Java provides a huge library of pre-written classes Sometimes these classes are exactly what you need Sometimes these classes are almost what you need It s easy to subclass a class and override the methods that you want to behave differently Inheritance is a way of providing similar behavior to different kinds of objects, without duplicating code You should extend a class (and inherit from it) only if: Your new class really is a more specific kind of the superclass, and You want your new class to have most or all of the functionality of the class you are extending, and You need to add to or modify the capabilities of the superclass You should not extend a class merely to use some of its features

What are abstract classes for? Abstract classes are suitable when you can reasonably implement some, but not all, of the behavior of the subclasses Example: You have a game in which various kinds of animals move around and do things All animals can move(), eat(), drink(), hide(), etc. Since these are identical or similar, it makes sense to have a default move() method, a default drink(), etc. If you have a default draw() method, what would it draw? Since you probably never want an Animal object, but just specific animals (Zebra, Lion, etc.), you don t need to be able to instantiate the Animal class Make Animal abstract, with an abstract void draw() method

What are interfaces for? Inheritance lets you guarantee that subclass objects have the same methods as their superclass objects Interfaces let you guarantee that unrelated objects have the same methods Problem: Your GUI has an area in which it needs to draw some object, but you don t know yet what kind of object it will be Solution: Define a Drawable interface, with a method draw() Make your tables, graphs, line drawings, etc., implement Drawable In your GUI, call the object s draw() method (legal for any Drawable object) If you didn t have interfaces, here s what you would have to do: if (obj instanceof Table) ((Table)obj).draw(); else if (obj instanceof Graph) ((Graph)obj).draw(); else if (obj instanceof LineDrawing) ((LineDrawing)obj).draw(); // etc. Worse, to add a new type of object, you have to change a lot of code

Using generic classes A generic class is a class that is parameterized with a type (rather than a value) Example: ArrayList<String> describes an ArrayList (the class) that can only hold Strings (the type) You can use a genericized class anywhere you can use any other type name Examples: ArrayList<Double> scores = new ArrayList<Double>(); ArrayList<Double> adjustscores(arraylist<double> scores) {...}

Access There are four types of access: public means accessible from everywhere protected means accessible from all classes in this same directory and accessible from all subclasses anywhere Package (default; no keyword) means accessible from all classes in this same directory private means accessible only within this class Note: Making a field private does not hide it from other objects in this same class! In general, it s best to make all variables as private as possible, and to make methods public enough to be used where they are needed

Methods A method may: be public, protected, package, or private be static or instance be final or nonfinal return a value or be void throw exceptions The signature of a method consists of its name and the number and types (in order) of its formal parameters You overload a method by writing another method with the same name but a different signature You override an inherited method by writing another method with the same signature

Proper use of methods Ideally, a method should do only one thing You should describe what it does in one simple sentence The method name should clearly convey the basic intent There is no such thing as a method that s too small Methods should usually do no input/output Unless, of course, that s the main purpose of the method Exception: Temporary print statements used for debugging Methods should do sanity checks on their inputs Publicly available methods should throw Exceptions for bad inputs