Lecture 26: Inheritance Announcements & Review Lab 8 Due Thursday Image and color effects with 2D arrays Last Time Images as 2D arrays color representation.

Slides:



Advertisements
Similar presentations
In our lesson today we will learn how to find the area of a building.
Advertisements

Lecture 10: Part 1: OO Issues CS 540 George Mason University.
Object Oriented Programming in Java. Object Oriented Programming Concepts in Java Object oriented Programming is a paradigm or organizing principle for.
Module 8 “Polymorphism and Inheritance”. Outline Understanding Inheritance Inheritance Diagrams Constructors in Derived Classes Type Compatibility Polymorphism.
Lecture 28: Abstract Classes & Inheritance Announcements & Review Lab 8 Due Thursday Image and color effects with 2D arrays Read: –Chapter 9 Cahoon & Davidson.
Inheritance Inheritance Reserved word protected Reserved word super
ACM/JETT Workshop - August 4-5, :Inheritance and Interfaces.
Inheritance. Extending Classes It’s possible to create a class by using another as a starting point  i.e. Start with the original class then add methods,
1 Inheritance Reserved word protected Reserved word super Overriding methods Class Hierarchies Reading for this lecture: L&L 8.1 – 8.5.
Inheritance. 2 Inheritance allows a software developer to derive a new class from an existing one The existing class is called the parent class or superclass.
©The McGraw-Hill Companies, Inc. Permission required for reproduction or display. 4 th Ed Chapter N - 1 Chapter 13 Polymorphism is-a relationships Interfaces.
Aalborg Media Lab 23-Jun-15 Inheritance Lecture 10 Chapter 8.
Lecture 32 Inheritance COMP1681 / SE15 Introduction to Programming.
CS102--Object Oriented Programming Review 1: Chapter 1 – Chapter 7 Copyright © 2008 Xiaoyan Li.
1 Topic 4 Inheritance "Question: What is the object oriented way of getting rich? Answer: Inheritance.“
Chapter 10 Classes Continued
©The McGraw-Hill Companies, Inc. Permission required for reproduction or display. 4 th Ed Chapter N - 1 Chapter 13 Polymorphism is-a relationships Interfaces.
Inheritance. © 2004 Pearson Addison-Wesley. All rights reserved 8-2 Inheritance Inheritance is a fundamental object-oriented design technique used to.
Liang, Introduction to Java Programming, Tenth Edition, (c) 2013 Pearson Education, Inc. All rights reserved. 1 Chapter 11 Inheritance and Polymorphism.
Lecture 3 Casting Abstract Classes and Methods Interfaces.
Sadegh Aliakbary Sharif University of Technology Fall 2010.
Sadegh Aliakbary. Copyright ©2014 JAVACUP.IRJAVACUP.IR All rights reserved. Redistribution of JAVACUP contents is not prohibited if JAVACUP.
CSC 142 O 1 CSC 142 Java More About Inheritance & Interfaces [Reading: chapter 13]
Chapter 8. About the Midterm Exam.. Exam on March 12 Monday (Tentatively) Review on March 7 Wednesday Cover from Chapter 6 Grades will be out before spring.
CSE 501N Fall ‘09 14: Inheritance 20 October 2009 Nick Leidenfrost.
Outline §Review of the last class l class variables and methods l method overloading and overriding §Inheritance and polymorphism l polymorphism l abstract.
Inheritance. What Is Inheritance? Familiar examples: –A family tree (individuals inherit characteristics from other individuals) –A taxonomy (classes.
Peyman Dodangeh Sharif University of Technology Fall 2014.
Topic 4 Inheritance.
Inheritance  Inheritance is a fundamental object-oriented technique  it enhances software design and promotes reuse  We will focus on:  deriving new.
Inheritance. Inheritance - Introduction Idea behind is to create new classes that are built on existing classes – you reuse the methods and fields and.
Lecture 24: Color Announcements & Review Lab 7 Due Thursday 2 D arrays - embedding graphs in an array Computer Science Artifacts Abstraction Representations.
(1) ICS 313: Programming Language Theory Chapter 12: Object Oriented Programming.
Inheritance CSI 1101 Nour El Kadri. OOP  We have seen that object-oriented programming (OOP) helps organizing and maintaining large software systems.
Application development with Java Lecture 21. Inheritance Subclasses Overriding Object class.
Coming up: Inheritance
1 Inheritance Reserved word protected Reserved word super Overriding methods Class Hierarchies Reading for this lecture: L&L 9.1 – 9.4.
Session 18 Lab 9 Re-cap, Chapter 12: Polymorphism & Using Sound in Java Applications.
ABSTRACT DATA TYPES, ABSTRACT CLASSES AND INTERFACES And abstract art….
Object-Oriented Programming (OOP) What we did was: (Procedural Programming) a logical procedure that takes input data, processes it, and produces output.
Inheritance in Java. Access Specifiers private keywordprivate keyword –Used for most instance variables –private variables and methods are accessible.
(c) University of Washington06-1 CSC 143 Java Inheritance Tidbits.
1 / 71 COP 3503 FALL 2012 SHAYAN JAVED LECTURE 4 Programming Fundamentals using Java 1.
Interfaces, Abstract Classes, and Polymorphism. What Is an Interface? An interface is the set of public methods in a class Java provides the syntax for.
Liang, Introduction to Java Programming, Tenth Edition, (c) 2013 Pearson Education, Inc. All rights reserved. 1 Chapter 11 Inheritance and Polymorphism.
CS 112 Programming 2 Lecture 06 Inheritance & Polymorphism (1)
Lecture 3: More on Classes Textbook: Chapter 2 Recap: –Classes vs. Objects –Q: What comes first a class or an object? –Q: Do we need a class to create.
Object Oriented Programming Lecture 3: Things OO.
Notices Assn 2 is due tomorrow, 7pm. Moodle quiz next week – written in the lab as before. Everything up to and including today’s lecture: Big Topics are.
CS100Lecture 61 Announcements Homework P1 due on Thursday Homework P2 handed out.
Inheritance, Polymorphism, and Interfaces 1 What’s past is prologue. Don’t write it twice — write it once and reuse it. Advanced Placement Computer Science.
Advanced Programming in Java
Inheritance ITI1121 Nour El Kadri.
Lecture 12 Inheritance.
Chapter 11 Inheritance and Polymorphism
Advanced Programming in Java
Week 4 Object-Oriented Programming (1): Inheritance
Introduction to Object-oriented Program Design
More inheritance, Abstract Classes and Interfaces
MSIS 670 Object-Oriented Software Engineering
Outline Writing Classes Copyright © 2012 Pearson Education, Inc.
Implementing Non-Static Features
Advanced Programming Behnam Hatami Fall 2017.
Advanced Java Programming
Announcements & Review
More About Inheritance & Interfaces
Chapter 11 Inheritance and Polymorphism
Object-Oriented Programming
Computer Science II for Majors
Presentation transcript:

Lecture 26: Inheritance Announcements & Review Lab 8 Due Thursday Image and color effects with 2D arrays Last Time Images as 2D arrays color representation –red, green, blue values –integer values expanding & shrinking –mapping from a point in one 2D space to another Today review & new object oriented concepts

Lecture 26: Inheritance Object Oriented Object Centered View Objects with attributes and behaviors –attributes: instance variables –behaviors: methods Designing a Class –use private for encapsulation scopes the instance variables to the class methods no one else can directly modify them –public methods for behaviors local variables “disappear” after the method returns –use private helper methods when necessary

Lecture 26: Inheritance Example Local vs Instance Variable public class Rectangle { private int width; // the instance variables private int height; public Rectangle() { width = 0; height = 0; } public Rectangle(int w, int h) { width = w; height = h; } public int getArea() { int area = width * height; // area is local variable // Aside: int width =... BAD PRACTICE, never name a local // variable the same name as an instance variable if (area > 0) { return area; } else { System.out.println (“Bad Rectangle”); } }

Lecture 26: Inheritance Why Inheritance? Reuse in common functionality in related classes Reduce redundancy, ease programmer effort Classification lets humans deal with complexity, inheritance is a form of classification General to specific, e.g., cat to siamese Read: –Chapter 9 Cahoon & Davidson –Chapter 9 Regis & Stepp Additional Reading:

Lecture 26: Inheritance Example Inheritance Hierarchy and Instance Variables Motor Vehicle CarTruckMotorcycle HarleyHondaKawasaki miles per gallon max speed... tires passengers seat storage cup holder... colors standard features extras

Lecture 26: Inheritance Inheritance in Java... Object TransformationGraphRectangle ColoredRectangle Object provides these methods: toString() equals() // more on these clone() // later... instanceof() All classes inherit from Object Rectangle inherits from Object ColoredRectangle inherits from Rectangle

Lecture 26: Inheritance Syntax of Inheritance Example: ColoredRectangle public class ColoredRectangle extends Rectangle { private Color myColor; // additional instance variables public ColoredRectangle() { super(); // optional myColor = Color.white; } // Is the same as: public ColoredRectangle() { // implicitly first calls super, because // the signatures match myColor = Color.white; } public ColoredRectangle(int w, int h, Color newColor) { super(w,h); // required: why do we need this one? myColor = newColor; } Also, we have to change Rectangle’s instance variables to protected