Question of the Day  Write valid mathematical equation using: 2 3 4 5 one addition operator (‘+’) one equality operator (‘=’)  Should have equal values.

Slides:



Advertisements
Similar presentations
Final and Abstract Classes
Advertisements

Lecture 5: Interfaces.
Abstract Class and Interface
Object Oriented Programming
Java Review Interface, Casting, Generics, Iterator.
METHOD OVERRIDING 1.Sub class can override the methods defined by the super class. 2.Overridden Methods in the sub classes should have same name, same.
Inheritance Lakshmish Ramaswamy. Example A Rectangle class with area method A Circle class with area method Array containing references to circles & rectangles.
Abstract Classes and Interfaces The objectives of this chapter are: To explore the concept of abstract classes To understand interfaces To understand the.
– Advanced Programming P ROGRAMMING IN Lecture 16 Interfaces.
Lecture 17 Abstract classes Interfaces The Comparable interface Event listeners All in chapter 10: please read it.
Programming with Java © 2002 The McGraw-Hill Companies, Inc. All rights reserved. 1 Chapter 12 More OOP, Interfaces, and Inner Classes.
Object-Oriented Design CSC 212. Announcements Ask more questions! If I am not making myself clear, it is your opportunity to explain what is confusing.
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.
1 Lecture 06(Abstract Classes)Lecture 9 Abstract Classes Overview  Abstract Classes: A Definition.  Declaring Abstract Classes.  Abstract Methods: A.
Slides prepared by Rose Williams, Binghamton University Chapter 13 Interfaces and Inner Classes.
June 1, 2000 Object Oriented Programming in Java (95-707) Java Language Basics 1 Lecture 3 Object Oriented Programming in Java Language Basics Classes,
1 Chapter 6 Inheritance, Interfaces, and Abstract Classes.
CPSC150 Abstract Classes and Interfaces Chapter 10.
CPSC150 Interfaces Chapter CPSC150 Inheritance Review No different than any other class. Has no access to or information about subclasses class.
Abstract Classes and Interfaces
Java Implementation Software Construction Lecture 6.
Question of the Day  Write valid mathematical equation using: one addition operator (‘+’) one equality operator (‘=’)  Should have equal values.
Polymorphism &Virtual Functions
1 Object-Oriented Software Engineering CS Interfaces Interfaces are contracts Contracts between software groups Defines how software interacts with.
Programming in Java Unit 2. Class and variable declaration A class is best thought of as a template from which objects are created. You can create many.
CSC 205 Java Programming II Polymorphism. Topics Polymorphism The principle of substitution Dynamic binding Object type casting Abstract class The canonical.
Question of the Day  On a game show you’re given the choice of three doors: Behind one door is a car; behind the others, goats. After you pick a door,
AP Computer Science A – Healdsburg High School 1 Interfaces, Abstract Classes and the DanceStudio - Similarities and Differences between Abstact Classes.
CSC 212 – Data Structures Lecture 11: More Inheritance & Generic Types.
OOP: Encapsulation,Abstraction & Polymorphism. What is Encapsulation Described as a protective barrier that prevents the code and data being randomly.
Chapter 3 Inheritance and Polymorphism Goals: 1.Superclasses and subclasses 2.Inheritance Hierarchy 3.Polymorphism 4.Type Compatibility 5.Abstract Classes.
LECTURE 9: INTERFACES & ABSTRACT CLASSES CSC 212 – Data Structures.
Question of the Day  Thieves guild states it will sell to members: lock picking kits  $0.67 each 40’ rope  $2.12 each Wire cutters  $4.49 each How.
2-Dec-15 Inner Classes By Alguien Soy. 2 Inner classes All the classes so far have been “top level” It is possible (and useful) to define a class inside.
Question of the Day  Thieves guild states it will sell to members: lock picking kits  $0.67 each 40’ rope  $2.12 each Wire cutters  $4.49 each How.
CS 61B Data Structures and Programming Methodology July 2, 2008 David Sun.
MIT AITI 2004 – Lecture 13 Abstract Classes and Interfaces.
Sadegh Aliakbary Sharif University of Technology Fall 2012.
Interfaces Chapter 9. 9 Creating Interfaces An interface is a contract. Every class that implements the interface must provide the interface’s defined.
Application development with Java Lecture 21. Inheritance Subclasses Overriding Object class.
 In the java programming language, a keyword is one of 50 reserved words which have a predefined meaning in the language; because of this,
Interfaces F What is an Interface? F Creating an Interface F Implementing an Interface F What is Marker Interface?
Chapter 11: Advanced Inheritance Concepts. Objectives Create and use abstract classes Use dynamic method binding Create arrays of subclass objects Use.
Quick Review of OOP Constructs Classes:  Data types for structured data and behavior  fields and methods Objects:  Variables whose data type is a class.
Inheritance and Polymorphism
Author: DoanNX Time: 45’.  OOP concepts  OOP in Java.
COP 3330 Notes 3/7. Today’s Topics Exceptions Abstract Classes.
Slides prepared by Rose Williams, Binghamton University ICS201 Lecture 7 : Interfaces King Fahd University of Petroleum & Minerals College of Computer.
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.
Lecture 6:Interfaces and Abstract Classes Michael Hsu CSULA.
Modern Programming Tools And Techniques-I
Web Design & Development Lecture 9
OOP: Encapsulation &Abstraction
Polymorphism, Abstract Classes & Interfaces
Interface.
Lecture 8: Polymorphism & Class Design
UML Class Diagram: class Rectangle
CS240: Advanced Programming Concepts
Interface.
Enumerations & Annotations
Introduction interface in Java is a blueprint of a class. It has static constants and abstract methods only. An interface is a way to describe what classes.
Java Programming Language
Interfaces.
Polymorphism, Abstract Classes & Interfaces
Chapter 14 Abstract Classes and Interfaces
Inner Classes 1-May-19.
Final and Abstract Classes
INTERFACES Explained By: Sarbjit Kaur. Lecturer, Department of Computer Application, PGG.C.G., Sector: 42, Chandigarh.
Presentation transcript:

Question of the Day  Write valid mathematical equation using: one addition operator (‘+’) one equality operator (‘=’)  Should have equal values on both sides of equals sign  Not limited to what is possible in Java

Question of the Day  Write valid mathematical equation using: one addition operator (‘+’) one equality operator (‘=’)  Should have equal values on both sides of equals sign  Not limited to what is possible in Java = 3 2

Interfaces in Real World  Everyone should give me colored paper in wallets  Men pictured on these unimportant papers  In return, will show you trip pictures (when I get back)

Interfaces in Real World  Everyone should give me colored paper in wallets  Men pictured on these unimportant papers  In return, will show you trip pictures (when I get back)

Interfaces in Real World  Everyone should give me colored paper in wallets  Men pictured on these unimportant papers  In return, will show you trip pictures (when I get back)

Interfaces in Real World

Interfaces  Can only declare important constant fields  public static final must be used for fields  Interface declares public abstract methods  Methods callable anywhere by any class  But method’s body cannot be defined in interface

Adding to an Interface  Interfaces have sub-interfaces  Sub-interface extends super-interface  Super-interface’s methods included in sub-interface  Methods from super-super-interface also inherited  Sub-interface can extend multiple interfaces  Methods not defined so no problems possible

Declaring Interfaces public interface Drawable { public void setColor(Color c); public Color getColor(); public void draw(Graphics g); } public interface TranDraw extends Drawable{ public void setTransparency(int tLevel); } public interface MoveDraw extends Drawable{ public void setPosition(int x, int y); }

Interfaces implement  Classes implement interfaces  Implementing classes define interface’s methods  Any number of interfaces may be implemented  Multiple inheritance issues ignored -- methods empty  Unrelated to superclass chosen or used by a class  Classes must implement all interface’s methods  Includes methods inherited from super-interface

Implementing Interfaces public class Square implements Drawable { private Color c; private int x, y, side; public Square(Color col, int len) { c = col; side = len; } public void setColor(Color col){ c=col; } public Color getColor() { return c; } public void draw(Graphics g) { g.drawRect(x, y, side, side, c); } }

Implementing Interfaces public class Oval implements Drawable { private Color c; private int x, y, majRad, minRad; public Oval(Color co, int maj, int min){ c = co; majRad = maj; minRad = min; } public void setColor(Color col){ c=col; } public Color getColor() { return c; } public void draw(Graphics g) { g.drawOval(x, y, majRad, minRad, c); } }

Using Interfaces

Interface Overview  Classes can implement interfaces instances  Both used to mark instances define method(s)  All variables can use interface or class as type  Abstact methods defined by interface  More flexible: class can implement many interfaces  Can mark classes; do not have to declare methods

Typecasting int i = 13; Square s = ((Square)i);  Only exist to “assist” compiler with code  Changes variable’s type so compilation continues  Not in *.class file – does not affect instance at all  Only when KNOW instance & variables types differ  Errors at runtime instead of during compilation  Illegal code will compile, but still illegal

Typecasting int i = 13; Square s = ((Square)i);  Only exist to “assist” compiler with code  Changes variable’s type so compilation continues  Not in *.class file – does not affect instance at all  Only when KNOW instance & variables types differ  Errors at runtime instead of during compilation  Illegal code will compile, but still illegal

Narrowing Conversions  Java cannot compile narrowing conversions  Assign interface variable to implementing class variable  Compiler will not allow it, but could be legal  Typecasting required for these assignments Drawable obj = new Oval(...);

Narrowing Conversions  Java cannot compile narrowing conversions  Assign interface variable to implementing class variable  Compiler will not allow it, but could be legal  Typecasting required for these assignments Drawable obj = new Oval(...); Oval sad = obj; //  Does not work

Narrowing Conversions  Java cannot compile narrowing conversions  Assign interface variable to implementing class variable  Compiler will not allow it, but could be legal  Typecasting required for these assignments Drawable obj = new Oval(...); Oval sad = obj; //  Does not work Oval glad = (Oval)obj; // works!

Your Turn  Get into your groups and complete activity

For Next Lecture  Read B.13 for Wed. and be ready to discuss  What is inheritance? extends  How does the extends keyword work?  How does inheritance compare to interfaces?  As usual, there is weekly assignment on Angel Tuesday  Due by 5PM Tuesday via Assignment Submitter  Each problem graded using provided JUnit tests