Интерфейсы и наследование. Интерфейсы Объявление public interface OperateCar { // constant declarations, if any // method signatures int turn(Direction.

Slides:



Advertisements
Similar presentations
Object Oriented Programming with Java
Advertisements

Java Implementation: Part 1 S CompSci 230 Software Construction.
Abstract Class and Interface
CS18000: Problem Solving and 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.
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.
Inheritance, part 2: Subclassing COMP 401, Fall 2014 Lecture 8 9/11/2014.
Sadegh Aliakbary Sharif University of Technology Fall 2010.
Lecture 17 Abstract classes Interfaces The Comparable interface Event listeners All in chapter 10: please read it.
Sub and superclasses using extends
CPSC150 Inheritance Details Chapter 9. CPSC150 Print in Entertainment ver 2 (with inheritance): public void print() { System.out.print("title: " + title.
UML Class Diagram: class Rectangle
Abstract Classes and Interfaces
Java Implementation Software Construction Lecture 6.
Lecture 3 Casting Abstract Classes and Methods Interfaces.
1 Object-Oriented Software Engineering CS Interfaces Interfaces are contracts Contracts between software groups Defines how software interacts with.
Interfaces and Inheritance. Interfaces  There are a number of situations in software engineering when it is important for disparate groups of programmers.
Lecture2: Java Basics Bohyung Han CSE, POSTECH CSED233: Data Structures (2014F)
Liang, Introduction to Java Programming, Sixth Edition, (c) 2005 Pearson Education, Inc. All rights reserved Chapter 2 1 Java Inheritance.
COP 2800 Lake Sumter State College Mark Wilson, Instructor.
Chris Kiekintveld CS 2401 (Fall 2010) Elementary Data Structures and Algorithms Inheritance and Polymorphism.
AP Computer Science A – Healdsburg High School 1 Interfaces, Abstract Classes and the DanceStudio - Similarities and Differences between Abstact Classes.
C# G 1 CSC 298 Object Oriented Programming Part 2.
Javax.swing Class JOptionPane Java.lang.Object java.awt.Component java.awt.Container javax.swing.JComponent javax.swing.JOptionPane.
Inheritance. Inheritance - Introduction Idea behind is to create new classes that are built on existing classes – you reuse the methods and fields and.
1 Abstract Classes and Interfaces. 2 The abstract Modifier  The abstract class –Cannot be instantiated –Should be extended and implemented in subclasses.
MIT AITI 2004 – Lecture 13 Abstract Classes and Interfaces.
Abstract Classes and Interfaces The Basics in Java.
JAVA METHODS and CONSTRUCTORS. 2 JAVA Classes The class is the fundamental concept in JAVA (and other OOPLs) A class describes some data object(s), and.
Chapter 7: Class Inheritance F Superclasses and Subclasses F Keywords: super and this F Overriding methods F The Object Class F Modifiers: protected, final.
1 COSC2007 Data Structures II Chapter 9 Class Relationships.
Chapter 8 Class Inheritance and Interfaces F Superclasses and Subclasses  Keywords: super F Overriding methods  The Object Class  Modifiers: protected,
 In the java programming language, a keyword is one of 50 reserved words which have a predefined meaning in the language; because of this,
©The McGraw-Hill Companies, Inc. Permission required for reproduction or display. Chapter Chapter 13 Inheritance and Polymorphism.
OOP: Inheritance. Inheritance A class can extend another class, inheriting all its data members and methods while redefining some of them and/or adding.
A Java program consists of a set of class definitions, optionally grouped into packages. Each class encapsulates state and behavior appropriate to whatever.
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.
1 Chapter 8 Class Inheritance and Interfaces F Superclasses and Subclasses  Keywords: super F Overriding methods  The Object Class  Modifiers: protected,
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.
Interfaces & Abstract Classes (For CS III AP) March 2014.
CS 116 Object Oriented Programming II Lecture 9 Acknowledgement: Contains materials provided by George Koutsogiannakis and Matt Bauer.
1 COMP9024: Data Structures and Algorithms Week One: Java Programming Language (II) Hui Wu Session 2, 2014
Lecture 5:Interfaces and Abstract Classes Michael Hsu CSULA.
Classes CS 162 (Summer 2009). Parts of a Class Instance Fields Methods.
Lecture 6:Interfaces and Abstract Classes Michael Hsu CSULA.
Lecture 5:Interfaces and Abstract Classes
Modern Programming Tools And Techniques-I
COMP9024: Data Structures and Algorithms
Abstract classes and interfaces
More About Java and Java How to Program By Deitel & Deitel.
COMP9024: Data Structures and Algorithms
Interfaces.
Inheritance and Polymorphism
Refactoring Methods: Kevin Murphy.
University of Central Florida COP 3330 Object Oriented Programming
03/10/14 Chapter 9 Inheritance.
EEC 484 Computer Networks Java Tutorial #1 Wenbing Zhao
UML Class Diagram: class Rectangle
Abstract classes and interfaces
null, true, and false are also reserved.
Interface.
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 ,
CSC 113: Computer programming II
Abstract classes and interfaces
Chapter 8 Class Inheritance and Interfaces
Inheritance Lakshmish Ramaswamy.
Presentation transcript:

Интерфейсы и наследование

Интерфейсы Объявление public interface OperateCar { // constant declarations, if any // method signatures int turn(Direction direction, double radius, double startSpeed); int changeLanes(Direction direction, double startSpeed, double endSpeed); } Реализация public class OperateBMW760i implements OperateCar { // the OperateCar method signatures, with implementation, for example: int signalTurn(Direction direction, boolean signalOn) { // code to turn BMW's LEFT turn indicator lights on // code to turn BMW's LEFT turn indicator lights off } // other members, as needed -- for example, helper classes not // visible to clients of the interface }

Расширение Интерфейсов public interface GroupedInterface extends Interface1, Interface2, Interface3 { // constant declarations // base of natural logarithms double E = ; // method signatures void doSomething (int i, double x); int doSomethingElse(String s); }

Наследование public class Bicycle { //implement } public class MountainBike extends Bicycle { // the MountainBike subclass adds one field public int seatHeight; // the MountainBike subclass has one constructor public MountainBike(int startHeight, int startCadence, int startSpeed, int startGear) { super(startCadence, startSpeed, startGear); seatHeight = startHeight; }

Приведение типов MountainBike myBike = new MountainBike(0, 0, 0, 0); Object obj = new MountainBike(0, 0, 0, 0); MountainBike myBike1 = (MountainBike)obj; if (obj instanceof MountainBike) { MountainBike myBike2 = (MountainBike)obj; }

Полиморфизм Демо TestBike

Final и Астрактны Классы Final final class ChessAlgorithm { enum ChessPlayer { WHITE, BLACK }... final ChessPlayer getFirstPlayer() { return ChessPlayer.WHITE; }... } Abstract public abstract class GraphicObject { // declare fields // declare non-abstract methods abstract void draw(); }

Q&A