Welcome to Scribd, the world's digital library. Read, publish, and share books and documents. See more
Download
Standard view
Full view
of .
Look up keyword
Like this
3Activity
0 of .
Results for:
No results containing your search query
P. 1
Java LaptrinhOOP

Java LaptrinhOOP

Ratings:

4.0

(2)
|Views: 194 |Likes:
Published by api-3834030

More info:

Published by: api-3834030 on Oct 18, 2008
Copyright:Attribution Non-commercial

Availability:

Read on Scribd mobile: iPhone, iPad and Android.
download as DOC, PDF, TXT or read online from Scribd
See more
See less

03/18/2014

pdf

text

original

L\u00e2\u0323 p tri\u0300nh h\u01b0\u01a1\u0301ng \u0111\u00f4\u0301i t\u01b0\u01a1\u0323 ng trong Java
Ch\u01b0\u01a1ng : L\u00c2\u0323 P TRINH H\u01af\u01a0\u0301NG \u0110\u00d4\u0301I T\u01af\u01a0\u0323 NG TRONG JAVA
Java la\u0300 m\u00f4\u0323
t ng\u00f4n ng\u01b0\u0303 l\u00e2\u0323 p tri\u0300nh h\u01b0\u01a1\u0301ng \u0111\u00f4\u0301i t\u01b0\u01a1\u0323 ng. N\u00ea\u0301u ba\u0323 n ch\u01b0a bao gi\u01a1\u0300 du\u0300ng m\u00f4\u0323

t ng\u00f4n ng\u01b0\u0303 l\u00e2\u0323 p tri\u0300nh h\u01b0\u01a1\u0301ng \u0111\u00f4\u0301i t\u01b0\u01a1\u0323 ng tr\u01b0\u01a1\u0301c \u0111\u00e2y, ba\u0323 n c\u00e2\u0300n pha\u0309i hi\u00ea\u0309u ca\u0301c kha\u0301i ni\u00ea\u0323 m sau : l\u00e2\u0323 p tri\u0300nh h\u01b0\u01a1\u0301ng \u0111\u00f4\u0301i t\u01b0\u01a1\u0323 ng (Object Oriented Programming) la\u0300 gi\u0300 ? \u0111\u00f4\u0301i t\u01b0\u01a1\u0323 ng (Object), l\u01a1\u0301p (class) la\u0300 gi\u0300, m\u00f4\u0301

i quan
h\u00ea\u0323 gi\u01b0\u0303a \u0111\u00f4\u0301i t\u01b0\u01a1\u0323 ng va\u0300 l\u01a1\u0301p, g\u01a1\u0309i th\u00f4ng \u0111i\u00ea\u0323 p (Messages) \u0111\u00ea\u0301n ca\u0301c \u0111\u00f4\u0301i t\u01b0\u01a1\u0323 ng la\u0300 gi\u0300 ?
I. KHA\u0301I NI\u00ca\u0323 M L\u00c2\u0323 P TRINH H\u01af\u01a0\u0301NG \u0110\u00d4\u0301I T\u01af\u01a0\u0323 NG
1. L\u00e2\u0323 p tri\u0300 nh h\u01b0\u01a1\u0301ng \u0111\u00f4\u0301i t\u01b0\u01a1\u0323 ng (Object Oriented Programming)
M\u00f4\u0303i m\u00f4\u0323

t ch\u01b0\u01a1ng tri\u0300nh ma\u0301y ti\u0301nh \u0111\u00ea\u0300u g\u00f4\u0300m co\u0301 2 ph\u00e2\u0300n : ph\u00e2\u0300n ma\u0303 l\u00ea\u0323 nh va\u0300 ph\u00e2\u0300n d\u01b0\u0303 li\u00ea\u0323 u. M\u00f4\u0323 t s\u00f4\u0301 ch\u01b0\u01a1ng tri\u0300nh \u0111\u0103\u0323 t tro\u0323 ng t\u00e2m \u01a1\u0309 ph\u00e2\u0300n ma\u0303 l\u00ea\u0323 nh, s\u00f4\u0301 kha\u0301c \u0111\u0103\u0323 t tro\u0323 ng t\u00e2m \u01a1\u0309 ph\u00e2\u0300n d\u01b0\u0303 li\u00ea\u0323 u. T\u01b0\u0300 \u0111o\u0301 d\u00e2\u0303n \u0111\u00ea\u0301n 2 m\u00f4 hi\u0300nh quy\u00ea\u0301t \u0111i\u0323 nh n\u00ean c\u00e2\u0301u tru\u0301c cu\u0309a ch\u01b0\u01a1ng tri\u0300nh : m\u00f4\u0323

t tra\u0309 l\u01a1\u0300i cho c\u00e2u ho\u0309i \u201c\u0110i\u00ea\u0300u gi\u0300 \u0111ang
xa\u0309y ra\u201d, va\u0300 m\u00f4\u0323 t cho \u201cCa\u0301i gi\u0300 \u0111ang chi\u0323 u ta\u0301c \u0111\u00f4\u0323 ng\u201d. M\u00f4 hi\u0300nh 1 go\u0323 i la\u0300 m\u00f4 hi\u0300nh h\u01b0\u01a1\u0301ng x\u01b0\u0309 ly\u0301
, no\u0301 m\u00f4
ta\u0309 nh\u01b0 la\u0300 m\u00f4\u0323 t ch\u01b0\u01a1ng tri\u0300nh bao g\u00f4\u0300m m\u00f4\u0323
t chu\u00f4\u0303i ca\u0301c b\u01b0\u01a1\u0301c th\u01b0\u0323 c hi\u00ea\u0323 n (ma\u0303 l\u00ea\u0323 nh). Nh\u01b0ng khi ch\u01b0\u01a1ng
tri\u0300nh ca\u0300ng nga\u0300 y ca\u0300ng l\u01a1\u0301n va\u0300 ph\u01b0\u0301c ta\u0323 p thi\u0300 kho\u0301 kh\u0103n \u0111\u00ea\u0309 s\u01b0\u0309 du\u0323 ng m\u00f4 hi\u0300nh th\u01b0\u0301 nh\u00e2\u0301t.

Vi\u0300 v\u00e2\u0323 y m\u00f4 hi\u0300nh th\u01b0\u0301 2 \u0111\u01b0\u01a1\u0323 c \u0111\u01b0a ra, \u0111o\u0301 la\u0300 m\u00f4 hi\u0300nh h\u01b0\u01a1\u0301ng \u0111\u00f4\u0301i t\u01b0\u01a1\u0323 ng. Ch\u01b0\u01a1ng tri\u0300nh cu\u0309a ba\u0323 n se\u0303 x\u00e2y d\u01b0\u0323 ng d\u01b0\u0323 a va\u0300o d\u01b0\u0303 li\u00ea\u0323 u va\u0300 ph\u00e2\u0300n giao di\u00ea\u0323 n \u0111\u01b0\u01a1\u0323 c \u0111i\u0323 nh nghi\u0303a cho ph\u00e2\u0300n d\u01b0\u0303 li\u00ea\u0323 u \u0111o\u0301. M\u00f4 hi\u0300nh na\u0300 y \u0111\u01b0\u01a1\u0323 c m\u00f4 ta\u0309 nh\u01b0 la\u0300 d\u01b0\u0303 li\u00ea\u0323 u \u0111i\u00ea\u0300u khi\u00ea\u0309n truy xu\u00e2\u0301t \u0111\u00f4\u0301i v\u01a1\u0301i ma\u0303 l\u00ea\u0323 nh.

Ng\u00f4n ng\u01b0\u0303 l\u00e2\u0323 p tri\u0300nh h\u01b0\u01a1\u0301ng \u0111\u00f4\u0301i t\u01b0\u01a1\u0323 ng co\u0301 ca\u0301c kha\u0309 n\u0103ng sau :
- M\u00f4 pho\u0309ng th\u00ea\u0301 gi\u01a1\u0301i th\u01b0\u0323 c m\u00f4\u0323

t ca\u0301ch t\u01b0\u0323 nhi\u00ean b\u01a1\u0309i ca\u0301c \u0111\u00f4\u0301i t\u01b0\u01a1\u0323 ng va\u0300 m\u00f4\u0301i quan h\u00ea\u0323 gi\u01b0\u0303a chu\u0301ng, thu\u00e2\u0323 n
ti\u00ea\u0323 n cho vi\u00ea\u0323 c thi\u00ea\u0301t k\u00ea\u0301 h\u00ea\u0323 th\u00f4\u0301ng ph\u01b0\u0301c ta\u0323 p
- Th\u01b0\u0300a k\u00ea\u0301 ma\u0303 co\u0301 s\u0103\u0303n m\u00f4\u0323 t ca\u0301ch d\u00ea\u0303 da\u0300ng, giu\u0301p ti\u00ea\u0301t ki\u00ea\u0323 m c\u00f4ng s\u01b0\u0301c va\u0300 n\u00e2ng cao n\u0103ng su\u00e2\u0301t cu\u0309a ng\u01b0\u01a1\u0300i
l\u00e2\u0323 p tri\u0300nh, d\u00ea\u0303 ba\u0309o tri\u0300, d\u00ea\u0303 n\u00e2ng c\u00e2\u0301p, m\u01a1\u0309 r\u00f4\u0323 ng

2. Tr\u01b0\u0300 u t\u01b0\u01a1\u0323 ng hoa\u0301 (Abstraction)
Con ng\u01b0\u01a1\u0300i \u0111a\u0303 \u0111\u01a1n gia\u0309n hoa\u0301 ca\u0301c v\u00e2\u0301n \u0111\u00ea\u0300 ph\u01b0\u0301c ta\u0323 p th\u00f4ng qua s\u01b0\u0323 tr\u01b0\u0300u t\u01b0\u01a1\u0323 ng hoa\u0301. Vi\u0301 du\u0323 ,
ng\u01b0\u01a1\u0300i s\u01b0\u0309 du\u0323 ng ma\u0301y ti\u0301nh kh\u00f4ng nhi\u0300n ma\u0301y ti\u0301nh m\u00f4\u0323

t ca\u0301ch ph\u01b0\u0301c ta\u0323 p. Nh\u01a1\u0300 s\u01b0\u0323 tr\u01b0\u0300u t\u01b0\u01a1\u0323 ng hoa\u0301 ma\u0300 ng\u01b0\u01a1\u0300i ta co\u0301 th\u00ea\u0309 s\u01b0\u0309 du\u0323 ng ma\u0301y ti\u0301nh ma\u0300 kh\u00f4ng quan t\u00e2m \u0111\u00ea\u0301n c\u00e2\u0301u tru\u0301c chi ti\u00ea\u0301t b\u00ean trong ma\u0301y ti\u0301nh. Ho\u0323 chi\u0309 s\u01b0\u0309 du\u0323 ng chu\u0301ng nh\u01b0 la\u0300 m\u00f4\u0323

t th\u01b0\u0323 c th\u00ea\u0309

Ca\u0301ch t\u00f4\u0301t nh\u00e2\u0301t \u0111\u00ea\u0309 n\u0103\u0301m v\u01b0\u0303ng ky\u0303 thu\u00e2\u0323 t tr\u01b0\u0300u t\u01b0\u01a1\u0323 ng la\u0300 du\u0300ng h\u00ea\u0323 th\u00f4\u0301ng ph\u00e2n c\u00e2\u0301p. \u0110i\u00ea\u0300u na\u0300 y cho phe\u0301p ba\u0323 n ph\u00e2n l\u01a1\u0301p ca\u0301c tha\u0300nh ph\u00e2\u0300n co\u0301 y\u0301 nghi\u0303a cu\u0309a ca\u0309 h\u00ea\u0323 th\u00f4\u0301ng ph\u01b0\u0301c ta\u0323 p, chia nho\u0309 chu\u0301ng tha\u0300nh nh\u01b0\u0303ng ph\u00e2\u0300n \u0111\u01a1n gia\u0309n co\u0301 th\u00ea\u0309 qua\u0309n ly\u0301 \u0111\u01b0\u01a1\u0323 c. Nhi\u0300n b\u00ean ngoa\u0300i ma\u0301y ti\u0301nh la\u0300 m\u00f4\u0323

t \u0111\u00f4\u0301i t\u01b0\u01a1\u0323 ng, n\u00ea\u0301u nhi\u0300n s\u00e2u h\u01a1n m\u00f4\u0323 t c\u00e2\u0301p, ma\u0301y ti\u0301nh bao g\u00f4\u0300m m\u00f4\u0323 t s\u00f4\u0301 b\u00f4\u0323 ph\u00e2\u0323 n : h\u00f4\u0323 p \u0111i\u00ea\u0300u khi\u00ea\u0309n, ma\u0300n hi\u0300nh, ba\u0300n phi\u0301m, chu\u00f4\u0323 t..., ca\u0301c b\u00f4\u0323 ph\u00e2\u0323 n na\u0300y la\u0323 i bao g\u00f4\u0300m ca\u0301c b\u00f4\u0323 ph\u00e2\u0323 n nho\u0309 h\u01a1n, vi\u0301 du\u0323 nh\u01b0 h\u00f4\u0323 p \u0111i\u00ea\u0300u khi\u00ea\u0309n co\u0301 ba\u0309ng ma\u0323

ch chi\u0301nh ch\u01b0\u0301a CPU, ca\u0301c ma\u0323
ch giao ti\u00ea\u0301p g\u0103\u0301n tr\u00ean ba\u0309ng ma\u0323 ch chi\u0301nh, \u0111i\u0303a c\u01b0\u0301ng, \u00f4\u0309 \u0111i\u0303a m\u00ea\u0300m\u2026
Nh\u01a1\u0300 s\u01b0\u0323 tr\u01b0\u0300u t\u01b0\u01a1\u0323 ng hoa\u0301 ma\u0300 ba\u0323 n kh\u00f4ng quan t\u00e2m \u0111\u00ea\u0301n chi ti\u00ea\u0301t t\u01b0\u0300ng ba\u0309ng ma\u0323
ch, ma\u0300 chi\u0309 quan t\u00e2m
m\u00f4\u0301

i quan h\u00ea\u0323 , giao ti\u00ea\u0301p gi\u01b0\u0303a ca\u0301c b\u00f4\u0323 ph\u00e2\u0323 n. M\u00f4\u0323 t ma\u0323 ch giao ti\u00ea\u0301p du\u0300 co\u0301 ch\u01b0\u0301c n\u0103ng ly ky\u0300 th\u00ea\u0301 na\u0300o \u0111i n\u01b0\u0303a, ba\u0323 n co\u0301 th\u00ea\u0309 s\u01b0\u0309 du\u0323 ng kh\u00f4ng m\u00e2\u0301y kho\u0301 kh\u0103n n\u00ea\u0301u \u0111\u01b0\u01a1\u0323 c \u00e2\u0301n v\u01b0\u0300a v\u0103\u0323 n va\u0300o khe c\u0103\u0301m tr\u00ean ba\u0309ng ma\u0323 ch chi\u0301nh.

S\u01b0\u0323 ph\u00e2n c\u00e2\u0301p tr\u01b0\u0300u t\u01b0\u01a1\u0323 ng m\u00f4\u0323
t h\u00ea\u0323 th\u00f4\u0301ng ph\u01b0\u0301c ta\u0323 p co\u0301 th\u00ea\u0309 a\u0301p du\u0323 ng cho ca\u0301c ch\u01b0\u01a1ng tri\u0300nh ma\u0301y
ti\u0301nh. Ph\u00e2\u0300n d\u01b0\u0303 li\u00ea\u0323 u t\u01b0\u0300 m\u00f4\u0323

t ch\u01b0\u01a1ng tri\u0300nh h\u01b0\u01a1\u0301ng x\u01b0\u0309 ly\u0301 kinh \u0111i\u00ea\u0309n co\u0301 th\u00ea\u0309 tr\u01b0\u0300u t\u01b0\u01a1\u0323 ng hoa\u0301 tha\u0300nh ca\u0301c \u0111\u00f4\u0301i t\u01b0\u01a1\u0323 ng tha\u0300nh ph\u00e2\u0300n. Da\u0303y ca\u0301c x\u01b0\u0309 ly\u0301 tr\u01a1\u0309 tha\u0300nh ca\u0301c th\u00f4ng \u0111i\u00ea\u0323 p gi\u01b0\u0303a ca\u0301c \u0111\u00f4\u0301i t\u01b0\u01a1\u0323 ng. Vi\u0300 th\u00ea\u0301 ca\u0301c \u0111\u00f4\u0301i t\u01b0\u01a1\u0323 ng c\u00e2\u0300n co\u0301 hoa\u0323 t \u0111\u00f4\u0323 ng \u0111\u0103\u0323 c tr\u01b0ng ri\u00eang. Ba\u0323 n co\u0301 th\u00ea\u0309 coi ca\u0301c \u0111\u00f4\u0301i t\u01b0\u01a1\u0323 ng na\u0300 y nh\u01b0 nh\u01b0\u0303ng th\u01b0\u0323 c th\u00ea\u0309 \u0111\u00f4\u0323 c l\u00e2\u0323 p ti\u00ea\u0301p nh\u00e2\u0323 n ca\u0301c y\u00eau c\u00e2\u0300u t\u01b0\u0300 b\u00ean ngoa\u0300i. \u0110\u00e2y la\u0300 ph\u00e2\u0300n c\u00f4\u0301t lo\u0303i cu\u0309a l\u00e2\u0323 p tri\u0300nh h\u01b0\u01a1\u0301ng \u0111\u00f4\u0301i t\u01b0\u01a1\u0323 ng.

II. C\u01a0 CH\u00ca\u0301 TRI\u00ca\u0309N KHAI M\u00d4 HINH H\u01af\u01a0\u0301NG \u0110\u00d4\u0301I T\u01af\u01a0\u0323
NG
T\u00e2\u0301t ca\u0309 ca\u0301c ng\u00f4n ng\u01b0\u0303 l\u00e2\u0323 p tri\u0300nh h\u01b0\u01a1\u0301ng \u0111\u00f4\u0301i t\u01b0\u01a1\u0323 ng \u0111\u00ea\u0300u co\u0301 ca\u0301c c\u01a1 ch\u00ea\u0301 cho phe\u0301p ba\u0323 n tri\u00ea\u0309n khai
ca\u0301c m\u00f4 hi\u0300nh h\u01b0\u01a1\u0301ng \u0111\u00f4\u0301i t\u01b0\u01a1\u0323 ng. \u0110o\u0301 la\u0300 ti\u0301nh \u0111o\u0301ng go\u0301i, k\u00ea\u0301 th\u01b0\u0300a, va\u0300 ti\u0301nh \u0111a hi\u0300nh.
1
L\u00e2\u0323 p tri\u0300nh h\u01b0\u01a1\u0301ng \u0111\u00f4\u0301i t\u01b0\u01a1\u0323 ng trong Java
1. Ti\u0301nh \u0111o\u0301ng go\u0301i (Encapsulation)
\u0110\u00e2y la\u0300 c\u01a1 ch\u00ea\u0301 du\u0300ng m\u00f4\u0323 t vo\u0309 bo\u0323 c k\u00ea\u0301t h\u01a1\u0323 p ph\u00e2\u0300n d\u01b0\u0303 li\u00ea\u0323 u va\u0300 ca\u0301c thao ta\u0301c tr\u00ean d\u01b0\u0303 li\u00ea\u0323 u \u0111o\u0301 (ph\u00e2\u0300n
ma\u0303 l\u00ea\u0323 nh) tha\u0300nh m\u00f4\u0323
t th\u00ea\u0309 th\u00f4\u0301ng nh\u00e2\u0301t, ta\u0323 o n\u00ean s\u01b0\u0323 an toa\u0300n, tra\u0301nh vi\u00ea\u0323 c s\u01b0\u0309 du\u0323 ng kh\u00f4ng \u0111u\u0301ng thi\u00ea\u0301t k\u00ea\u0301,
ba\u0309o v\u00ea\u0323 cho ma\u0303 l\u00ea\u0323 nh va\u0300 d\u01b0\u0303 li\u00ea\u0323 u ch\u00f4\u0301ng vi\u00ea\u0323 c truy xu\u00e2\u0301t t\u01b0\u0300 nh\u01b0\u0303ng \u0111oa\u0323 n ma\u0303 l\u00ea\u0323 nh b\u00ean ngoa\u0300i.

Trong Java ti\u0301nh \u0111o\u0301ng go\u0301i th\u00ea\u0309 hi\u00ea\u0323 n qua kha\u0301i ni\u00ea\u0323 m l\u01a1\u0301p (Class). L\u01a1\u0301p la\u0300 ha\u0323 t nh\u00e2n cu\u0309a Java, ta\u0323 o n\u00ea\u0300n ta\u0309ng cho l\u00e2\u0323 p tri\u0300nh h\u01b0\u01a1\u0301ng \u0111\u00f4\u0301i t\u01b0\u01a1\u0323 ng trong Java. No\u0301 \u0111i\u0323 nh nghi\u0303a d\u01b0\u0303 li\u00ea\u0323 u va\u0300 ca\u0301c ha\u0300nh vi cu\u0309a no\u0301 (d\u01b0\u0303 li\u00ea\u0323 u va\u0300 ma\u0303 l\u00ea\u0323 nh), go\u0323 i la\u0300 ca\u0301c tha\u0300nh vi\u00ean cu\u0309a l\u01a1\u0301p, du\u0300ng chung cho ca\u0301c \u0111\u00f4\u0301i t\u01b0\u01a1\u0323 ng cu\u0300ng loa\u0323 i. T\u01b0\u0300 s\u01b0\u0323 ph\u00e2n ti\u0301ch h\u00ea\u0323 th\u00f4\u0301ng, ng\u01b0\u01a1\u0300 i ta tr\u01b0\u0300u t\u01b0\u01a1\u0323 ng n\u00ean ca\u0301c l\u01a1\u0301p. Sau \u0111o\u0301 ca\u0301c \u0111\u00f4\u0301i t\u01b0\u01a1\u0323 ng \u0111\u01b0\u01a1\u0323 c ta\u0323 o ra theo khu\u00f4n m\u00e2\u0303u cu\u0309a l\u01a1\u0301p. M\u00f4\u0303i \u0111\u00f4\u0301i t\u01b0\u01a1\u0323 ng thu\u00f4\u0323 c m\u00f4\u0323 t l\u01a1\u0301p co\u0301 d\u01b0\u0303 li\u00ea\u0323 u va\u0300 ha\u0300nh vi \u0111i\u0323 nh nghi\u0303a cho l\u01a1\u0301p \u0111o\u0301, gi\u00f4\u0301ng nh\u01b0 la\u0300 sinh ra t\u01b0\u0300 m\u00f4\u0323 t khu\u00f4n \u0111u\u0301c cu\u0309a l\u01a1\u0301p \u0111o\u0301. Vi\u0300 v\u00e2\u0323 y ma\u0300 l\u01a1\u0301p la\u0300 khu\u00f4n m\u00e2\u0303

u cu\u0309a \u0111\u00f4\u0301i t\u01b0\u01a1\u0323 ng,
\u0111\u00f4\u0301i t\u01b0\u01a1\u0323 ng la\u0300 th\u00ea\u0309 hi\u00ea\u0323 n cu\u0309a m\u00f4\u0323 t l\u01a1\u0301p. L\u01a1\u0301p la\u0300 c\u00e2\u0301u tru\u0301c logic, co\u0300n \u0111\u00f4\u0301i t\u01b0\u01a1\u0323 ng la\u0300 c\u00e2\u0301u tru\u0301c v\u00e2\u0323 t ly\u0301

. D\u01b0\u0303 li\u00ea\u0323 u \u0111i\u0323 nh nghi\u0303a trong l\u01a1\u0301p go\u0323 i la\u0300 bi\u00ea\u0301n, ma\u0303 l\u00ea\u0323 nh go\u0323 i la\u0300 ph\u01b0\u01a1ng th\u01b0\u0301c. Ph\u01b0\u01a1ng th\u01b0\u0301c \u0111i\u0323 nh nghi\u0303a cho vi\u00ea\u0323 c s\u01b0\u0309 du\u0323 ng d\u01b0\u0303 li\u00ea\u0323 u nh\u01b0 th\u00ea\u0301 na\u0300o. \u0110i\u00ea\u0300u na\u0300 y co\u0301 nghi\u0303a la\u0300 hoa\u0323 t \u0111\u00f4\u0323 ng cu\u0309a l\u01a1\u0301p \u0111\u01b0\u01a1\u0323 c \u0111i\u0323 nh nghi\u0303a th\u00f4ng qua ph\u01b0\u01a1ng th\u01b0\u0301c.

Ca\u0301c \u0111\u0103\u0323 c tr\u01b0ng cu\u0309a l\u01a1\u0301p g\u00f4\u0300m co\u0301 hai ph\u00e2\u0300n chi\u0301nh : thu\u00f4\u0323 c ti\u0301nh (Attribute) va\u0300 ha\u0300nh vi (Behavior). Gia\u0309 s\u01b0\u0309 ba\u0323 n pha\u0309i ta\u0323 o ra giao di\u00ea\u0323 n v\u01a1\u0301i ng\u01b0\u01a1\u0300i du\u0300ng va\u0300 c\u00e2\u0300n co\u0301 nh\u01b0\u0303ng nu\u0301t nh\u00e2\u0301n (Button). Th\u00ea\u0301 thi\u0300 tr\u01b0\u01a1\u0301c h\u00ea\u0301t ba\u0323 n x\u00e2y d\u01b0\u0323 ng l\u01a1\u0301p Button v\u01a1\u0301i ca\u0301c thu\u00f4\u0323 c ti\u0301nh nh\u01b0 nha\u0303n ghi tr\u00ean nu\u0301t, chi\u00ea\u0300u r\u00f4\u0323 ng, chi\u00ea\u0300u cao, ma\u0300u cu\u0309a nu\u0301t, \u0111\u00f4\u0300ng th\u01a1\u0300i quy \u0111i\u0323 nh ha\u0300nh vi cu\u0309a nu\u0301t nh\u00e2\u0301n, nghi\u0303a la\u0300 nu\u0301t nh\u00e2\u0301n c\u00e2\u0300n pha\u0309n \u01b0\u0301ng nh\u01b0 th\u00ea\u0301 na\u0300o khi \u0111\u01b0\u01a1\u0323 c cho\u0323 n, pha\u0301t y\u00eau c\u00e2\u0300u gi\u0300, co\u0301 \u0111\u00f4\u0309i ma\u0300u hay nh\u00e2\u0301p nha\u0301y chi kh\u00f4ng. V\u01a1\u0301i l\u01a1\u0301p Button nh\u01b0 v\u00e2\u0323 y, ba\u0323 n co\u0301 th\u00ea\u0309 ta\u0323 o ra nhanh cho\u0301ng nh\u01b0\u0303ng nu\u0301t nh\u00e2\u0301n cu\u0323 th\u00ea\u0309 phu\u0323 c vu\u0323 cho ca\u0301c mu\u0323 c \u0111i\u0301ch kha\u0301c nhau

Go\u0301i la\u0300 ky\u0303 thu\u00e2\u0323 t cu\u0309a Java, du\u0300ng \u0111\u00ea\u0309 ph\u00e2n hoa\u0323 ch kh\u00f4ng gian t\u00ean l\u01a1\u0301p, giao di\u00ea\u0323 n tha\u0300nh
nh\u01b0\u0303ng vu\u0300ng d\u00ea\u0303 qua\u0309n ly\u0301 h\u01a1n, th\u00ea\u0309 hi\u00ea\u0323 n ti\u0301nh \u0111o\u0301ng go\u0301i cu\u0309a Java.
2. Ti\u0301nh k\u00ea\u0301 th\u01b0\u0300 a (Inheritance)

Ti\u0301nh k\u00ea\u0301 th\u01b0\u0300a la\u0300 kha\u0309 n\u0103ng x\u00e2y d\u01b0\u0323 ng ca\u0301c l\u01a1\u0301p m\u01a1\u0301i t\u01b0\u0300 ca\u0301c l\u01a1\u0301p \u0111a\u0303 co\u0301. Ti\u0301nh \u0111o\u0301ng go\u0301i cu\u0303ng ta\u0301c \u0111\u00f4\u0323 ng \u0111\u00ea\u0301n ti\u0301nh k\u00ea\u0301 th\u01b0\u0300a. Khi l\u01a1\u0301p \u0111o\u0301ng go\u0301i m\u00f4\u0323 t s\u00f4\u0301 d\u01b0\u0303 li\u00ea\u0323 u va\u0300 ph\u01b0\u01a1ng th\u01b0\u0301c, l\u01a1\u0301p m\u01a1\u0301i se\u0303 k\u00ea\u0301 th\u01b0\u0300a mo\u0323 i c\u00e2\u0301u tru\u0301c d\u01b0\u0303 li\u00ea\u0323 u va\u0300 ca\u0301c ph\u01b0\u01a1ng th\u01b0\u0301c cu\u0309a l\u01a1\u0301p ma\u0300 no\u0301 k\u00ea\u0301 th\u01b0\u0300a. Ngoa\u0300i ra no\u0301 co\u0301 th\u00ea\u0309 b\u00f4\u0309 sung ca\u0301c d\u01b0\u0303 li\u00ea\u0323 u va\u0300 ca\u0301c ph\u01b0\u01a1ng th\u01b0\u0301c cu\u0309a ri\u00eang mi\u0300

nh.
No\u0301 r\u00e2\u0301t quan tro\u0323 ng vi\u0300 no\u0301 \u01b0\u0301ng du\u0323 ng cho kha\u0301i ni\u00ea\u0323 m c\u00e2y ph\u00e2n c\u00e2\u0301p (m\u00f4 hi\u0300nh TopDown).
Kh\u00f4ng s\u01b0\u0309 du\u0323 ng c\u00e2y ph\u00e2n l\u01a1\u0301p, m\u00f4\u0303
i l\u01a1\u0301p pha\u0309i \u0111i\u0323 nh nghi\u0303a t\u00e2\u0301t ca\u0309 ca\u0301c d\u01b0\u0303 li\u00ea\u0323 u va\u0300 ph\u01b0\u01a1ng th\u01b0\u0301c cu\u0309a
mi\u0300
nh m\u00f4\u0323
t ca\u0301ch ro\u0303 ra\u0300ng. N\u00ea\u0301u s\u01b0\u0309 du\u0323 ng s\u01b0\u0323 k\u00ea\u0301 th\u01b0\u0300a, m\u00f4\u0303
i l\u01a1\u0301p chi\u0309 c\u00e2\u0300n \u0111i\u0323 nh nghi\u0303a th\u00eam nh\u01b0\u0303ng \u0111\u0103\u0323 c
tr\u01b0ng cu\u0309a mi\u0300
nh.
Vi\u0301 du\u0323 :Xe co\u0301 th\u00ea\u0309 xem nh\u01b0 m\u00f4\u0323

t l\u01a1\u0301p va\u0300 ca\u0301c xe Pergout, BWM, Dream la\u0300 ca\u0301c \u0111\u00f4\u0301i t\u01b0\u01a1\u0323 ng cu\u0309a l\u01a1\u0301p xe. Ca\u0301c xe \u0111\u00ea\u0300u co\u0301 th\u00ea\u0309 la\u0301i \u0111i, d\u01b0\u0300ng la\u0323 i... T\u01b0\u0300 l\u01a1\u0301p xe \u01a1\u0309 tr\u00ean, ta co\u0301 th\u00ea\u0309 x\u00e2y d\u01b0\u0323 ng ca\u0301c l\u01a1\u0301p xe \u0111a\u0323 p, xe \u00f4t\u00f4. Xe \u00f4t\u00f4 co\u0301 th\u00eam ma\u0301y va\u0300 co\u0301 th\u00ea\u0309 t\u01b0\u0323 kh\u01a1\u0309i \u0111\u00f4\u0323 ng\u2026

3. Ti\u0301nh \u0111a hi\u0300nh (Polymorphism)
Khi m\u00f4\u0323

t l\u01a1\u0301p \u0111\u01b0\u01a1\u0323 c k\u00ea\u0301 th\u01b0\u0300a t\u01b0\u0300 ca\u0301c l\u01a1\u0301p t\u00f4\u0309 ti\u00ean thi\u0300 no\u0301 co\u0301 th\u00ea\u0309 thay \u0111\u00f4\u0309i ca\u0301ch th\u01b0\u0301c la\u0300m vi\u00ea\u0323 c cu\u0309a l\u01a1\u0301p t\u00f4\u0309 ti\u00ean trong m\u00f4\u0323 t s\u00f4\u0301 ph\u01b0\u01a1ng th\u01b0\u0301c na\u0300o \u0111o\u0301 (nh\u01b0ng t\u00ean, ki\u00ea\u0309u tra\u0309 v\u00ea\u0300, danh sa\u0301ch tham \u0111\u00f4\u0301i cu\u0309a ph\u01b0\u01a1ng th\u01b0\u0301c thi\u0300 v\u00e2\u0303n gi\u01b0\u0303 nguy\u00ean). \u0110i\u00ea\u0300u na\u0300y go\u0323 i la\u0300 vi\u00ea\u0301t ch\u00f4\u0300ng. Nh\u01b0 v\u00e2\u0323 y v\u01a1\u0301i m\u00f4\u0323

t t\u00ean ph\u01b0\u01a1ng th\u01b0\u0301c, ch\u01b0\u01a1ng tri\u0300nh co\u0301 th\u00ea\u0309 co\u0301 ca\u0301c ha\u0300nh \u0111\u00f4\u0323 ng kha\u0301c nhau tu\u0300y thu\u00f4\u0323 c va\u0300o l\u01a1\u0301p cu\u0309a \u0111\u00f4\u0301i t\u01b0\u01a1\u0323 ng go\u0323 i ph\u01b0\u01a1ng th\u01b0\u0301c. \u0110o\u0301 la\u0300 ti\u0301nh \u0111a hi\u0300nh

Vi\u0301 du\u0323 : v\u01a1\u0301i m\u00f4\u0323
t ph\u01b0\u01a1ng th\u01b0\u0301c cha\u0323 y, xe \u00f4t\u00f4, xe ma\u0301y co\u0301 th\u00ea\u0309 t\u0103ng ga, co\u0300 n xe \u0111a\u0323 p thi\u0300 pha\u0309i \u0111a\u0323 p\u2026
Ti\u0301nh \u0111a hi\u0300nh co\u0300n th\u00ea\u0309 hi\u00ea\u0323 n \u01a1\u0309 vi\u00ea\u0323 c m\u00f4\u0323 t giao di\u00ea\u0323 n co\u0301 th\u00ea\u0309 s\u01b0\u0309 du\u0323 ng cho ca\u0301c hoa\u0323 t \u0111\u00f4\u0323 ng cu\u0309a m\u00f4\u0323
t

l\u01a1\u0301p t\u00f4\u0309ng qua\u0301t, hay co\u0300n go\u0323 i la\u0300 \u201cm\u00f4\u0323 t giao di\u00ea\u0323 n, nhi\u00ea\u0300u ph\u01b0\u01a1ng th\u01b0\u0301c\u201d. Co\u0301 nghi\u0303a la\u0300 co\u0301 th\u00ea\u0309 thi\u00ea\u0301t k\u00ea\u0301 m\u00f4\u0323 t giao di\u00ea\u0323 n t\u00f4\u0309ng qua\u0301t cho m\u00f4\u0323 t nho\u0301m ca\u0301c ha\u0300nh vi li\u00ean quan. \u0110i\u00ea\u0300u na\u0300y gia\u0309m thi\u00ea\u0309u s\u01b0\u0323 ph\u01b0\u0301c ta\u0323 p b\u0103\u0300ng ca\u0301ch cho phe\u0301p m\u00f4\u0323

t giao di\u00ea\u0323 n co\u0301 th\u00ea\u0309 s\u01b0\u0309 du\u0323 ng cho ca\u0301c hoa\u0323 t \u0111\u00f4\u0323 ng cu\u0309a m\u00f4\u0323

t l\u01a1\u0301p t\u00f4\u0309ng qua\u0301t. Tri\u0300nh bi\u00ean di\u0323 ch se\u0303 xa\u0301c \u0111i\u0323 nh hoa\u0323 t \u0111\u00f4\u0323 ng cu\u0323 th\u00ea\u0309 na\u0300o se\u0303 \u0111\u01b0\u01a1\u0323 c thi ha\u0300nh tu\u0300 y theo \u0111i\u00ea\u0300u ki\u00ea\u0323 n. Ba\u0323 n chi\u0309 c\u00e2\u0300n nh\u01a1\u0301 ca\u0301c giao di\u00ea\u0323 n cu\u0309a l\u01a1\u0301p t\u00f4\u0309ng qua\u0301t va\u0300 s\u01b0\u0309 du\u0323 ng no\u0301.

2
L\u00e2\u0323 p tri\u0300nh h\u01b0\u01a1\u0301ng \u0111\u00f4\u0301i t\u01b0\u01a1\u0323 ng trong Java
S\u01b0\u0323 k\u00ea\u0301t h\u01a1\u0323 p \u0111u\u0301ng \u0111\u0103\u0301n gi\u01b0\u0303a : \u0111a hi\u0300nh, \u0111o\u0301ng go\u0301i va\u0300 k\u00ea\u0301 th\u01b0\u0300a ta\u0323 o n\u00ean m\u00f4\u0323

t m\u00f4i tr\u01b0\u01a1\u0300ng l\u00e2\u0323 p tri\u0300nh co\u0301 kha\u0309 n\u0103ng pha\u0301t tri\u00ea\u0309n t\u00f4\u0301t h\u01a1n r\u00e2\u0301t nhi\u00ea\u0300u so v\u01a1\u0301i m\u00f4i tr\u01b0\u01a1\u0300ng kh\u00f4ng h\u00f4\u0303 tr\u01a1\u0323 h\u01b0\u01a1\u0301ng \u0111\u00f4\u0301i t\u01b0\u01a1\u0323 ng. M\u00f4\u0323 t c\u00e2y ph\u00e2n c\u00e2\u0301p l\u01a1\u0301p thi\u00ea\u0301t k\u00ea\u0301 t\u00f4\u0301t la\u0300 \u0111i\u00ea\u0300u c\u0103n ba\u0309n cho vi\u00ea\u0323 c s\u01b0\u0309 du\u0323 ng la\u0323 i nh\u01b0\u0303ng \u0111oa\u0323 n ma\u0303 l\u00ea\u0323 nh ma\u0300 ba\u0323 n \u0111a\u0303 t\u00f4\u0301n c\u00f4ng s\u01b0\u0301c nhi\u00ea\u0300u cho vi\u00ea\u0323 c pha\u0301t tri\u00ea\u0309n va\u0300 ki\u00ea\u0309m tra. Ti\u0301nh \u0111o\u0301ng go\u0301i cho phe\u0301p ba\u0323 n s\u01b0\u0309 du\u0323 ng ca\u0301c \u0111\u00f4\u0301i t\u01b0\u01a1\u0323 ng va\u0300 ra l\u00ea\u0323 nh thi ha\u0300nh t\u01a1\u0301i chu\u0301ng ma\u0300 kh\u00f4ng pha\u0301 v\u01a1\u0303 c\u00e2\u0301u tru\u0301c ca\u0301c \u0111oa\u0323 n ma\u0303 l\u00ea\u0323 nh \u0111a\u0303 ba\u0309o v\u00ea\u0323 b\u01a1\u0309i giao di\u00ea\u0323 n cu\u0309a ca\u0301c l\u01a1\u0301p. S\u01b0\u0323 \u0111a hi\u0300nh cho phe\u0301p ba\u0323 n ta\u0323 o ra nh\u01b0\u0303ng \u0111oa\u0323 n ma\u0303 l\u00ea\u0323 nh go\u0323 n ga\u0300ng, d\u00ea\u0303 \u0111o\u0323 c, d\u00ea\u0303 hi\u00ea\u0309u va\u0300 co\u0301 ti\u0301nh \u00f4\u0309n \u0111i\u0323 nh.

Java la\u0300 ng\u00f4n ng\u01b0\u0303 l\u00e2\u0323 p tri\u0300nh h\u01b0\u01a1\u0301ng \u0111\u00f4\u0301i t\u01b0\u01a1\u0323 ng n\u00ean co\u0301 \u0111\u00e2\u0300y \u0111u\u0309 ca\u0301c ti\u0301nh n\u0103ng tr\u00ean, th\u01b0
vi\u00ea\u0323 n l\u01a1\u0301p Java \u0111\u01b0\u01a1\u0323 c cung c\u00e2\u0301p kha\u0301 \u0111\u00e2\u0300 y \u0111u\u0309 cho ng\u01b0\u01a1\u0300 i l\u00e2\u0323 p tri\u0300nh \u0111\u00ea\u0309 b\u0103\u0301t \u0111\u00e2\u0300u m\u00f4\u0323
t d\u01b0\u0323 a\u0301n m\u01a1\u0301i
3

Activity (3)

You've already reviewed this. Edit your review.
1 hundred reads
1 thousand reads
rambo liked this

You're Reading a Free Preview

Download
/*********** DO NOT ALTER ANYTHING BELOW THIS LINE ! ************/ var s_code=s.t();if(s_code)document.write(s_code)//-->