object-oriented programming 8

17
CHAPTER 8 ABSTRACT & INTERFACE Mr.Warawut Khangkhan e-Mail: [email protected] Social Media: www.facebook.com/AjWarawut

Upload: warawut

Post on 18-Nov-2014

640 views

Category:

Education


2 download

DESCRIPTION

Abstract & Interface

TRANSCRIPT

Page 1: Object-Oriented Programming 8

CHAPTER 8

ABSTRACT & INTERFACEMr.Warawut Khangkhan

e-Mail: [email protected]

Social Media: www.facebook.com/AjWarawut

Page 2: Object-Oriented Programming 8

Mr.W

ara

wut K

hangkhan

Chapte

r 8 T

hre

ad

AABSTRACTBSTRACT

Chapte

r 8 T

hre

ad

2

Page 3: Object-Oriented Programming 8

AABSTRACTBSTRACT CCLASSLASS

����������� ������ ��������� ����������

Abstract Method

�Abstract Method �� ��� ��������� ����

Mr.W

ara

wut

Khangkhan

Chapte

r 8 T

hre

ad�������� �������!���� ��"#�

��������� $�%&��'%������������# %���� �� ���(��� �

��������������)� ���� ������������ ����!����� �

�"�����*�� � %��%������ $�%&��'��� +�������*,�����#*�� ���

��� Overriding Method 3

Chapte

r 8 T

hre

ad

Page 4: Object-Oriented Programming 8

AABSTRACTBSTRACT CCLASSLASS

������)����$ �%�� Abstract Class %��� �

� ������� ����- � Abstract Method !��

��$.���� ��� �%��%�� ���!�������� � �%���#

Abstract Class �"� �./��!������ ��� ����

Mr.W

ara

wut

Khangkhan

Chapte

r 8 T

hre

adAbstract Class �"� �./��!������ ��� ����

�������� �������*��*��&��� ��� %�����*�� �./��!���

��� �����*� Implementation ���*����"�� +���

%�������� �!���*� Implementation ���**��

Concrete Method4

Thre

ad

Page 5: Object-Oriented Programming 8

���������������� AABSTRACTBSTRACT CCLASSLASS

� abstract

Mr.W

ara

wut

Khangkhan

Chapte

r 8 T

hre

ad

abstract class abstract class abstract class abstract class AbstractClassNameAbstractClassNameAbstractClassNameAbstractClassName {{{{

[[[[AbstractMethodNamesAbstractMethodNamesAbstractMethodNamesAbstractMethodNames]]]]

[[[[ConcreteMethodNamesConcreteMethodNamesConcreteMethodNamesConcreteMethodNames]]]]

}}}}

5

Thre

ad

}}}}

AbstractMethodNames

������*�- ���������0 Abstract Method

�������� ��� � ������*�- ��.�� ��"�� ����

+����� �� ������ � 1 ��� �

Page 6: Object-Oriented Programming 8

���������������� AABSTRACTBSTRACT CCLASSLASS

Mr.W

ara

wut

Khangkhan

Chapte

r 8 T

hre

ad

class class class class ClassNameClassNameClassNameClassName extends extends extends extends AbstractClassNameAbstractClassNameAbstractClassNameAbstractClassName {{{{

AbstractMethodNamesAbstractMethodNamesAbstractMethodNamesAbstractMethodNames( ) {( ) {( ) {( ) {

[Statements];[Statements];[Statements];[Statements];

}}}}

6

Thre

ad

}}}}

}}}}

Page 7: Object-Oriented Programming 8

Mr.W

ara

wut

Khangkhan

Chapte

r 8 T

hre

ad

Thre

ad

7

Page 8: Object-Oriented Programming 8

Mr.W

ara

wut K

hangkhan

Chapte

r 8 T

hre

ad

IINTERFACENTERFACE

Thre

ad

8

Page 9: Object-Oriented Programming 8

IINTERFACENTERFACE

�����������.���� ����� Abstract Method

+���� �����1��*�������"$�����*�-� �)���,�!� ���������

-� �)�����-� �)���,�!�

Mr.W

ara

wut

Khangkhan

Chapte

r 8 T

hre

ad

9

Chapte

r 8 T

hre

ad

Page 10: Object-Oriented Programming 8

���������������� IINTERFACENTERFACE

� abstract

Mr.W

ara

wut

Khangkhan

Chapte

r 8 T

hre

ad

[modifier] interface [modifier] interface [modifier] interface [modifier] interface InterfaceNameInterfaceNameInterfaceNameInterfaceName {{{{

}}}}

Interface Abstract Method

10

Thre

ad

Interface ���� $��*� Abstract Method

�������*�"$ Abtract Class %���� �

implements ,��� �'�2���� ���� �1�� � ���������

��� ����!�� Abstract Method �� �%��� ��������

$�%&��'���

Page 11: Object-Oriented Programming 8

���������������� IINTERFACENTERFACEM

r.Wara

wut

Khangkhan

Chapte

r 8 T

hre

ad

[modifier] class [modifier] class [modifier] class [modifier] class ClassNameClassNameClassNameClassName implements implements implements implements

InterfaceNameInterfaceNameInterfaceNameInterfaceName {{{{

AbstractMethodNamesAbstractMethodNamesAbstractMethodNamesAbstractMethodNames( ) {( ) {( ) {( ) {

[Statements];[Statements];[Statements];[Statements];

}}}}

11

Thre

ad}}}}

}}}}

Example Ch08_02.java

Page 12: Object-Oriented Programming 8

��� � ������������� � ���������� AABSTRACTBSTRACT CCLASSLASS

������ IINTERFACENTERFACE

�Abstract Class ������������� $��*���� �

2 �$$ �� �$$�� ������� ���� (Concrete

Method) ����$$����� ������� ����

(Abstract Method) ���� � Abstract

Mr.W

ara

wut

Khangkhan

Chapte

r 8 T

hre

ad(Abstract Method) ���� � Abstract

Class ��!����� %��$����� �������(� ������� ����!������)������"����

12

Thre

ad

Page 13: Object-Oriented Programming 8

��� � ������������� � ���������� AABSTRACTBSTRACT CCLASSLASS

������ IINTERFACENTERFACE

�Interface ����������"����� ������� ���� ���� ���

� � Interface ��!�����!����� ���%��� �� �������

����!���"$��� �!� Interface �"#��� ����

����*�� ������� � Implements Interface

Mr.W

ara

wut

Khangkhan

Chapte

r 8 T

hre

ad����*�� ������� � Implements Interface

13

Thre

ad

Page 14: Object-Oriented Programming 8

��� � ������������� � ���������� AABSTRACTBSTRACT CCLASSLASS

������ IINTERFACENTERFACE

�����!�3 %���$ � Abstract Class ����1���������*����"#�

�����!�3 %�!����� Interface �������*�������

Interface Interface

Mr.W

ara

wut

Khangkhan

Chapte

r 8 T

hre

adInterface ���%��!�� Interface �����

Multiple Inheritance ���

14

Thre

ad

Page 15: Object-Oriented Programming 8

Mr.W

ara

wut K

hangkhan

Chapte

r 8 T

hre

ad

MULTIPLE INHERITANCE

Thre

ad

15

Page 16: Object-Oriented Programming 8

MMULTIPLEULTIPLE IINHERITANCENHERITANCE

��� �������$ ��.4�"�54�%�� SuperClass ��

����3 ���� ���(��� ��)� SubClass �1������

���* ���� ���� Amphibian ��$ ��.4��$"�,��

%������ Car �"$����

Mr.W

ara

wut

Khangkhan

Chapte

r 8 T

hre

ad%������ Car �"$����

Boat �"��"#�

���� Amphibian%���� ��,$,*�'������ �

��%��"#� 2 ����16

Chapte

r 8 T

hre

ad

Page 17: Object-Oriented Programming 8

�������������������������������� MMULIPLEULIPLE

IINTERFACENTERFACE

� abstract

Mr.W

ara

wut

Khangkhan

Chapte

r 8 T

hre

ad

[modifier] class [modifier] class [modifier] class [modifier] class ClassNameClassNameClassNameClassName implements implements implements implements

InterfaceName_InterfaceName_InterfaceName_InterfaceName_1111, InterfaceName_, InterfaceName_, InterfaceName_, InterfaceName_2222, …, , …, , …, , …,

InterfaceName_nInterfaceName_nInterfaceName_nInterfaceName_n {{{{

17

Thre

ad

}}}}