Announcements & Review

Slides:



Advertisements
Similar presentations
Chapter 13 Abstraction and inheritance. This chapter discusses n Implementing abstraction. u extension u inheritance n Polymorphism/dynamic binding. n.
Advertisements

Object Oriented Programming with Java
Object-Oriented Programming. 2 An object, similar to a real-world object, is an entity with certain properties, and with the ability to react in certain.
SUMMARY: abstract classes and interfaces 1 Make a class abstract so instances of it cannot be created. Make a method abstract so it must be overridden.
INTERFACES IN JAVA 1.Java Does not support Multiple Inheritance directly. Multiple inheritance can be achieved in java by the use of interfaces. 2.We need.
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.
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 Lecture 3 Inheritance. 2 A class that is inherited is called superclass The class that inherits is called subclass A subclass is a specialized version.
Inheritance Part II. Lecture Objectives To learn about inheritance To understand how to inherit and override superclass methods To be able to invoke superclass.
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]
Computer Science [3] Java Programming II - Laboratory Course Lab 1 + 2: Review inheritance & abstract Review inheritance & abstractPolymorphism Faculty.
CSC 205 Java Programming II Polymorphism. Topics Polymorphism The principle of substitution Dynamic binding Object type casting Abstract class The canonical.
Programming With Java ICS201 University Of Hail1 Chapter 13 Interfaces.
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.
Inheritance. Inheritance - Introduction Idea behind is to create new classes that are built on existing classes – you reuse the methods and fields and.
Object Oriented Programming
Lecture 26: Inheritance Announcements & Review Lab 8 Due Thursday Image and color effects with 2D arrays Last Time Images as 2D arrays color representation.
Coming up: Inheritance
(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.
OOP in Java : © W. Milner 2005 : Slide 1 Java and OOP Part 3 – Extending classes.
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.
Liang, Introduction to Java Programming, Seventh Edition, (c) 2009 Pearson Education, Inc. All rights reserved Chapter 10 Inheritance and Polymorphism.
CSC 205 Programming II Lecture 4 Abstract Class. The abstract keyword indicate that a class is not instantiable Defining a type which will be specialized.
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.
1 More About Derived Classes and Inheritance Chapter 9.
Java Interfaces CS 21a: Introduction to Computing I Department of Information Systems and Computer Science Ateneo de Manila University (see Chapter 9 of.
Week 21 Introduction to Programming Ms. Knudtzon C Period Lecture 3.
Class Inheritance Part II: Overriding and Polymorphism Corresponds with Chapter 10.
Lecture 21: Interfaces and Abstract classes
Advanced Programming in Java
Modern Programming Tools And Techniques-I
Inheritance Chapter 7 Inheritance Basics Programming with Inheritance
Abstract classes and interfaces
Chapter 15 Abstract Classes and Interfaces
Inheritance ITI1121 Nour El Kadri.
Lecture 12 Inheritance.
Object-oriented Programming in Java
Chapter 11 Inheritance and Polymorphism
Multi-Methods in Cecil
Inheritance and Polymorphism
Interface.
CMPUT 301: Lecture 06 Interfaces, Abstract classes and Inheritance
Java Inheritance.
Advanced Programming in Java
Continuing Chapter 11 Inheritance and Polymorphism
Inheritance "Question: What is the object oriented way of getting rich? Answer: Inheritance.“ “Inheritance is new code that reuses old code. Polymorphism.
Object Oriented Programming
Chapter 9 Inheritance and Polymorphism
Inheritance Chapter 5.
Abstract classes and interfaces
null, true, and false are also reserved.
Java Inheritance.
Polymorphism.
Advanced Programming Behnam Hatami Fall 2017.
Announcements Lab 8 Was Due Today Lab 7 Regrade Due Thursday
More About Inheritance & Interfaces
Chapter 14 Abstract Classes and Interfaces
Abstract classes and interfaces
Chapter 11 Inheritance and Polymorphism
Announcements & Review
Chapter 11 Inheritance and Encapsulation and Polymorphism
Topics OOP Review Inheritance Review Abstract Classes
Java Inheritance.
Computer Science II for Majors
Presentation transcript:

Announcements & Review Lab 8 Due Thursday Image and color effects with 2D arrays Read: Chapter 9 Cahoon & Davidson Chapter 9 Regis & Stepp Additional Reading: http://java.sun.com/docs/books/tutorial/java/concepts/inheritance.html Last Time Objects - attributes & behaviors Classification - Inheritance Today Review Inheritance Abstract Classes Lecture 27: Abstract Classes & Inheritance

Lecture 27: Abstract Classes & Inheritance Why Inheritance? Reuse of common functionality in related classes Reducing redundancy eases programmer effort Classification lets humans deal with complexity, inheritance is a form of classification General to specific, e.g., cat to siamese Lecture 27: Abstract Classes & Inheritance

Lecture 27: Abstract Classes & Inheritance Inheritance in Java ... All classes inherit from Object Rectangle inherits from Object ColoredRectangle inherits from Rectangle Object provides these methods: toString() equals() // more on these clone() // later... instanceof() Object Transformation Graph Rectangle ColoredRectangle Lecture 27: Abstract Classes & Inheritance

Super class: Rectangle public class Rectangle { protected int width; // the instance variables protected int height; public Rectangle() { width = 0; height = 0; } public Rectangle(int w, int h) { width = w; height = h; } public void draw(...) {} Lecture 27: Abstract Classes & 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 } */ public ColoredRectangle(int w, int h, Color newColor) { super(w,h); // required: why do we need this one? myColor = newColor; Lecture 27: Abstract Classes & Inheritance

Lecture 27: Abstract Classes & Inheritance Dynamic Dispatch Declare variables of supertype and they can be the supertype or the subtype Rectangle r = new ColoredRectangle(); Declare variables of a subtype and they can only be of type subtype or lower. Test type with instanceof <variable instanceof TypeName> returns a boolean if (r instanceof Rectangle) {...} if (r instanceof ColoredRectangle) {...} BlueJ Lecture 27: Abstract Classes & Inheritance

Lecture 27: Abstract Classes & Inheritance How can we partially declare a class? Example: Shape class with subtypes Rectangle and Triangle Is there a default draw method? Is there a default toString? Lecture 27: Abstract Classes & Inheritance

Syntax for Abstract Classes public abstract class Shapes { protected static String name; // Rectangle, Triangle, ... public abstract String toString(); // must implement toString public String getName() { return name; } public class Rectangle extends Shapes { protected static String name = “Rectangle”; .... public String toString() { Lecture 27: Abstract Classes & Inheritance

Lecture 27: Abstract Classes & Inheritance BlueJ examples ... Lecture 27: Abstract Classes & Inheritance