CSC 113: Computer programming II

Slides:



Advertisements
Similar presentations
Interfaces CSC 171 FALL 2004 LECTURE 14. Project 1 review public class Rational { private int numerator, denominator; public Rational(int numerator, int.
Advertisements

Object Oriented Programming
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.
Reusable Classes.  Motivation: Write less code!
Introduction to C# Erick Pranata © Sekolah Tinggi Teknik Surabaya 1.
Abstract Classes and Interfaces The objectives of this chapter are: To explore the concept of abstract classes To understand interfaces To understand the.
SE-1020 Dr. Mark L. Hornick 1 Inheritance and Polymorphism: Abstract Classes The “not quite” classes.
Lecture 17 Abstract classes Interfaces The Comparable interface Event listeners All in chapter 10: please read it.
Slides prepared by Rose Williams, Binghamton University Chapter 13 Interfaces and Inner Classes.
COP 3003 Object-Oriented Programming - Polymorphism Dr. Janusz Zalewski, Fall 2013 Prepared by Dr Dahai Guo.
Inheritance and Class Hierarchies Ellen Walker CPSC 201 Data Structures Hiram College.
1 Object-Oriented Software Engineering CS Interfaces Interfaces are contracts Contracts between software groups Defines how software interacts with.
Recitation 4 Abstract classes, Interfaces. A Little More Geometry! Abstract Classes Shape x ____ y ____ Triangle area() base____ height ____ Circle area()
AP Computer Science A – Healdsburg High School 1 Interfaces, Abstract Classes and the DanceStudio - Similarities and Differences between Abstact Classes.
Designing Classes Chapter 3. 2 Chapter Contents Encapsulation Specifying Methods Java Interfaces Writing an Interface Implementing an Interface An Interface.
Module 10: Inheritance in C#. Overview Deriving Classes Implementing Methods Using Sealed Classes Using Interfaces Using Abstract Classes.
Writing Static Methods Up until now, we have been USING (calling) static methods that other people have written. Now, we will start CREATING our own static.
Abstract Classes and Interfaces Chapter 9 CSCI 1302.
MIT AITI 2004 – Lecture 13 Abstract Classes and Interfaces.
Programming With Java ICS201 University Of Ha’il1 Chapter 7 Inheritance.
Lecture 21 - Abstract Classes and Interface. Example Figure –Rectangle –Triangle Figure –Dimensions –Area.
Chapter 7: Class Inheritance F Superclasses and Subclasses F Keywords: super and this F Overriding methods F The Object Class F Modifiers: protected, final.
Interfaces Chapter 9. 9 Creating Interfaces An interface is a contract. Every class that implements the interface must provide the interface’s defined.
Polymorphism CMPS Poly-morphism Means “many-forms” Means different things in biology, chemistry, computer science Means different things to functional.
Interfaces An interface is like an extreme case of an abstract class – However, an interface is not a class – It is a type that can be satisfied by any.
Side effects A side effect is anything that happens in a method other than computing and/or returning a value. Example: public class hello { public int.
Object Oriented programming Instructor: Dr. Essam H. Houssein.
© 2007 Lawrenceville Press Slide 1 Chapter 9 Inheritance  One class is an extension of another.  Allows a class to define a specialized type of an existing.
1 Interface &Implements. 2 An interface is a classlike construct that contains only constants variables and abstract methods definition. An interface.
CS102 – OOP_2 Inheritance, Polymorphism, Interfaces & Abstract classes. David Davenport.
Object orientation and Packaging in Java Object Orientation and Packaging Introduction: After completing this chapter, you will be able to identify.
UNIT-3 Interfaces & Packages. What is an Interface? An interface is similar to an abstract class with the following exceptions: All methods defined in.
POLYMORPHISM Chapter 6. Chapter Polymorphism  Polymorphism concept  Abstract classes and methods  Method overriding  Concrete sub classes and.
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.
Slides prepared by Rose Williams, Binghamton University ICS201 Lecture 7 : Interfaces King Fahd University of Petroleum & Minerals College of Computer.
Lecture 5:Interfaces and Abstract Classes Michael Hsu CSULA.
Java Interfaces CS 21a: Introduction to Computing I Department of Information Systems and Computer Science Ateneo de Manila University (see Chapter 9 of.
InterfacestMyn1 Interfaces Sometimes it is helpful to define what a class must do but not how it will do it. We have already seen an example of this: the.
Abstract classes and interfaces
More About Java and Java How to Program By Deitel & Deitel.
Inheritance and Polymorphism
EKT 472: Object Oriented Programming
One class is an extension of another.
Interface.
Encapsulation and Java Interface
Wrapper Classes ints, doubles, and chars are known as primitive types, or built-in types. There are no methods associated with these types of variables.
Interfaces.
Inheritance, Polymorphism, and Interfaces. Oh My
One class is an extension of another.
Class Inheritance (Cont.)
Object-Oriented Programming: Interface
Interface.
OBJECT ORIENTED PROGRAMMING II LECTURE 8 GEORGE KOUTSOGIANNAKIS
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.
Conditional Statements
Abstract Classes AKEEL AHMED.
Week 6 Object-Oriented Programming (2): Polymorphism
Interfaces.
Abstract Class As per dictionary, abstraction is the quality of dealing with ideas rather than events. For example, when you consider the case of ,
CSE 1030: Implementing GUI Mark Shtern.
Chapter 14 Abstract Classes and Interfaces
By Rajanikanth B OOP Concepts By Rajanikanth B
Abstract Classes and Interfaces
2009 Test Key.
Interface 11: Interface Programming C# © 2003 DevelopMentor, Inc.
Abstract Classes and Interfaces
Topics OOP Review Inheritance Review Abstract Classes
Inheritance Lakshmish Ramaswamy.
INTERFACES Explained By: Sarbjit Kaur. Lecturer, Department of Computer Application, PGG.C.G., Sector: 42, Chandigarh.
Presentation transcript:

CSC 113: Computer programming II Chapter 5: Interface CSC 113: Computer programming II

Interface An interface is a reference type, similar to a class, that can contain only constants and method signatures. To define an interface use the keyword interface instead of the keyword class. All method declarations in an interface are implicitly public, so you can omit the public modifier. A class must implement an interface A class implements an interface if it provides the method body to all abstract methods defined in the interface Interfaces cannot be instantiated—they can only be implemented by classes or extended by other interfaces. Extension is discussed later in this lesson.

Example public interface A { public void x(); public double y(); } public class B implements A { public void x(){ public double y(){ //Implements the body of y

ad , String ad

Same as for (int i=0; i < payableObjects.length; i++) { Payable currentPayable = payableObjects[i]; System.out.printf (---------------------------------); }

Derived Interfaces (Example) } } Interface Vampire extends DangerousMonster, Lethal { void drinkBlood(); } }