Interfaces and Abstract Classes

Slides:



Advertisements
Similar presentations
ABSTRACT CLASSES AND INTERFACES. Abstract methods You can declare an object without defining it: Person p; Similarly, you can declare a method without.
Advertisements

Inheritance Java permits you to use your user defined classes to create programs using inheritance.
Objectives Introduction to Inheritance and Composition (Subclasses and SuperClasses) Overriding (and extending), and inheriting methods and constructors.
Slides 4/22 COP Topics Final Exam Review Final Exam The final exam is Friday, April 29 th at 10:00 AM in the usual room No notes, books, calculators,
SE-1020 Dr. Mark L. Hornick 1 Inheritance and Polymorphism: Abstract Classes The “not quite” classes.
C HAPTER 7 Better Living in Objectville. O VERVIEW Understanding Inheritance Designing an Inheritance Tree Avoiding Duplicate Code Overriding Methods.
Exam Objective : Demonstrate the use of polymorphism PRESENTED BY: SRINIVAS VG.
Polymorphism & Methods COMP204 Bernhard Pfahringer (with lots of input from Mark Hall) poly + morphos (greek) “many forms”
CS 106 Introduction to Computer Science I 11 / 26 / 2007 Instructor: Michael Eckmann.
15-Jun-15 Abstract Classes and Interfaces. 2 Abstract methods You can declare an object without defining it: Person p; Similarly, you can declare a method.
CS 106 Introduction to Computer Science I 11 / 28 / 2007 Instructor: Michael Eckmann.
CS 106 Introduction to Computer Science I 11 / 15 / 2006 Instructor: Michael Eckmann.
©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 and Polymorphism Recitation 04/10/2009 CS 180 Department of Computer Science, Purdue University.
Abstract Classes and Interfaces. Abstract methods You can declare an object without defining it: Person p; Similarly, you can declare a method without.
©The McGraw-Hill Companies, Inc. Permission required for reproduction or display. 4 th Ed Chapter N - 1 Chapter 13 Polymorphism is-a relationships Interfaces.
Object-Orientated Design and Programming Unit 9: Abstract Classes and Interfaces Jin Sa.
CMSC 202 Interfaces. 11/20102 Classes and Methods When a class defines its methods as public, it describes how the class user interacts with the method.
CSE 331 Software Design & Implementation Hal Perkins Autumn 2012 Java Classes, Interfaces, and Types 1.
Polymorphism & Interfaces
CSC 142 O 1 CSC 142 Java More About Inheritance & Interfaces [Reading: chapter 13]
ECE 122 March 24. Motivation I am tasked to write two classes, one for cat, one for sheep. That is easy. I roll up my sleeve and get it done!
These materials where developed by Martin Schray. Please feel free to use and modify them for non-commercial purposes. If you find them useful or would.
Week111 APCS-AB: Java Inheritance November 17, 2005.
C# G 1 CSC 298 Object Oriented Programming Part 2.
Abstract Classes and Interfaces 5-Dec-15. Abstract methods You can declare an object without defining it: Person p; Similarly, you can declare a method.
Lecture 21 - Abstract Classes and Interface. Example Figure –Rectangle –Triangle Figure –Dimensions –Area.
Polymorphism & Methods COMP206 Geoff Holmes & Bernhard Pfahringer (these slides: lots of input from Mark Hall) poly + morphos (greek) “many forms”
CS 210 Introduction to OO Design August 24, 2006
(c) University of Washington05-1 CSC 143 Java Abstract Classes and Frameworks Reading: Ch. 11.
Further Abstraction Techniques Chapter 10. Abstract Classes There are times when you do not want someone to be able to make an object of your class. For.
This In Java, the keyword this allows an object to refer to itself. Or, in other words, this refers to the current object – the object whose method or.
COP INTERMEDIATE JAVA Inheritance, Polymorphism, Interfaces.
Comp1004: Inheritance II Polymorphism. Coming up Inheritance Reminder Overriding methods – Overriding and substitution Dynamic Binding Polymorphism –
Tutorial 2 Shane Paul. Contact Details Shane Paul Rm: 378 Ext: 82766
JAVA ACCESS MODIFIERS. Access Modifiers Access modifiers control which classes may use a feature. A classes features are: - The class itself - Its member.
Comp1004: Object Oriented Design I Abstract Classes and Interfaces.
Inheritance a subclass extends the functionality of a superclass a subclass inherits all the functionality of a superclass don't reinvent the wheel – "stand.
Coming up A quick word about abstract How a class interfaces
Abstract classes and interfaces
Web Design & Development Lecture 9
A Concrete Presentation on Abstract Classes and Methods, Interfaces, and Polymorphism CSC 202.
Abstract Classes and Interfaces
Abstract Classes and Interfaces
Abstract Classes and Interfaces
Interfaces.
Abstract Class, Interface, Package
Chapter 10 Thinking in Objects
More inheritance, Abstract Classes and Interfaces
Abstract classes and interfaces
CMSC 202 Interfaces.
Interfaces.
METHOD OVERRIDING in JAVA
Inheritance, Superclasses, Subclasses
CS18000: Problem Solving and Object-Oriented Programming
Abstract Classes Page
Inheritance Inheritance is a fundamental Object Oriented concept
Both/ Neither/Either/ All/ None
More About Inheritance & Interfaces
Chapter 9 Carrano Chapter 10 Small Java
Abstract Classes and Interfaces
Chapter 14 Abstract Classes and Interfaces
Inheritance and Polymorphism
Abstract classes and interfaces
Sampath Kumar S Assistant Professor, SECE
Abstract Classes and Interfaces
Abstract Classes and Interfaces
Topics OOP Review Inheritance Review Abstract Classes
CMSC 202 Interfaces.
មជ្ឈមណ្ឌលកូរ៉េ សហ្វវែរ អេច អ ឌី
Presentation transcript:

Interfaces and Abstract Classes I have wonderful news, mother. Joe finally implemented all his abstract methods! Now everything is working just the way we planned…

Abstract vs. Concrete Abstract Animal Concrete Canine Hippo Feline Dog Wolf Cat Lion Tiger

Abstract Classes You can not make a new instance of an abstract class! Abstract public class Canine extends Animal { public void roam() } An abstract class means the class must be extended

It really sucks to be an abstract method. You don’t have a body. Abstract Methods public abstract void eat(); There is not a method body, end it with a semicolon An interface includes abstract methods An abstract method means it must be overridden It really sucks to be an abstract method. You don’t have a body.

Making an Interface A Java interface is like a 100% pure abstract class! To define an Interface: Public interface Pet { public abstract void beFriendly(); public abstract void play(); } All methods in an interface are abstract, so any class that is – A Pet MUST implement (i.e. override) the methods of Pet.

Showing the Pet Interface Animal Canine Hippo Feline Dog Wolf Cat Lion Tiger

Implementing an Interface public class Dog extends Canine implements Pet { public void beFriendly() {……} public void play() {……} public void roam() {……} public void eat() {…….} } You must implement the pet methods! These are just normal overriding methods.

Forget about animals! Flier Interface What abstract methods would be needed for classes that fly Classes that implement the flier interface could be: Airplane Ski jumper ???? Write out the interface and the classes that implement it.

Instance Variables Does it make sense to say a Tub IS-A bathroom? Or a Bathroom IS-A Tub? Well it doesn’t to me. The relationship between my Tub and my Bathroom is HAS-A. Bathroom HAS-A Tub. That means Bathroom has a Tub instance variable.