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

Презентация:



Advertisements
Похожие презентации
2005 Pearson Education, Inc. All rights reserved. 1 Object-Oriented Programming: Interface.
Advertisements

1 © Luxoft Training 2012 Inner and anonymous classes.
Unit II Constructor Cont… Destructor Default constructor.
1/27 Chapter 9: Template Functions And Template Classes.
1/30 Chapter 8: Dynamic Binding And Abstract classes.
Интерфейсы в Java. Интерфейсы Множественное наследование не допускается при помощи классов Допускается множественное наследование при помощи интерфейсов.
Java Collections Framework (JCF) in Java Tutorial for students of universities Author: Oxana Dudnik.
1 © Luxoft Training 2012 Java basics Module 2. 2 © Luxoft Training 2012 Running Java application.
© Luxoft Training 2013 Java Collections API. © Luxoft Training 2013 Collections hierarchy.
2005 Pearson Education, Inc. All rights reserved. 1 Object-Oriented Programming: Polymorphism.
Классы и объекты. Декларация классов Обычный класс class MyClass { // field, constructor, and // method declarations } Класс наследованный class MyClass.
Test 11 Вопрос 1. class HashTest { private static Set set = new LinkedHashSet (); public static void main(String[] args) { set.add("one"); set.add("two");
2005 Pearson Education, Inc. All rights reserved Object-Oriented Programming: Inheritance.
© Luxoft Training 2013 Using Reflection API in Java.
© Luxoft Training 2013 Annotations. © Luxoft Training 2013 Java reflection / RTTI // given the name of a class, get a "Class" object that // has all info.
Test 14 Вопрос 1. class Main { public void method() { static class One { public One() { System.out.println("From one"); } } public static void main(String...
Test15 Вопрос 1. class AClass { } public class Test { public static void main (String... args) { ArrayList a = new ArrayList (); AClass aaaClass = new.
Object-Oriented Programming Dr. Ramzi Saifan Slides adapted from Prof. Steven Roehrig.
Test 10 Вопрос 1. public class Test implements Iterator { // 1 private List list = new ArrayList (); // 2 public void addList(T... ts) { Collections.addAll(list,
Object-Oriented Programme 1 SSD3: Object-Oriented Programming and Design.
Транксрипт:

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

Интерфейсы Объявление 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