CHAPTER 8 ABSTRACT & INTERFACE Mr.Warawut Khangkhan e-Mail: [email protected] Social Media: www.facebook.com/AjWarawut
CHAPTER 8
ABSTRACT & INTERFACEMr.Warawut Khangkhan
e-Mail: [email protected]
Social Media: www.facebook.com/AjWarawut
Mr.W
ara
wut K
hangkhan
Chapte
r 8 T
hre
ad
AABSTRACTBSTRACT
Chapte
r 8 T
hre
ad
2
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
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
���������������� 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 ��� �
���������������� 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
}}}}
}}}}
Mr.W
ara
wut
Khangkhan
Chapte
r 8 T
hre
ad
Thre
ad
7
Mr.W
ara
wut K
hangkhan
Chapte
r 8 T
hre
ad
IINTERFACENTERFACE
Thre
ad
8
IINTERFACENTERFACE
�����������.���� ����� Abstract Method
+���� �����1��*�������"$�����*�-� �)���,�!� ���������
-� �)�����-� �)���,�!�
Mr.W
ara
wut
Khangkhan
Chapte
r 8 T
hre
ad
9
Chapte
r 8 T
hre
ad
���������������� 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 �� �%��� ��������
$�%&��'���
���������������� 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
��� � ������������� � ���������� 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
��� � ������������� � ���������� AABSTRACTBSTRACT CCLASSLASS
������ IINTERFACENTERFACE
�Interface ����������"����� ������� ���� ���� ���
� � Interface ��!�����!����� ���%��� �� �������
����!���"$��� �!� Interface �"#��� ����
����*�� ������� � Implements Interface
Mr.W
ara
wut
Khangkhan
Chapte
r 8 T
hre
ad����*�� ������� � Implements Interface
13
Thre
ad
��� � ������������� � ���������� 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
Mr.W
ara
wut K
hangkhan
Chapte
r 8 T
hre
ad
MULTIPLE INHERITANCE
Thre
ad
15
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
�������������������������������� 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
}}}}