Ch ng 4: K th a
!"#
$%&'
(')
*)'
+,-
('"
!"#
Kế thừa ./'/0
+,1',234516789
6:;5 <5
'%%2
A
B
Lớp cha (lớp cơ sở)
Lớp con (lớp dẫn xuất)
=;<>6?'
Lớp Số
+, -, *, /
<,>,==,…
Giá trị
Lớp Số Thực
+, -, *, /
<,>,==,…
Giá trị thực
Lớp Số Nguyên
+, -, *, /
<,>,==,…
Giá trị nguyên
Lớp Phân Số
+, -, *, /
<,>,==,…
Giá trị mẫu số
Lớp Số Phức
+, -, *, /
<,>,==,…
Giá trị phức
$%&'
8'$%&
*/%!4)'8!4
Public"#%%5!4)/@A'5
A',6B%,CD@
Private)'!4/@A'5
%,6BE!4<'/%,
CD@
*/%6F-,6B8%&
(')
('"
G'"%'
(')
*%)8H8
95
public
private
('"
'661IHJ2K
LLML$A',C
D@
NO
'66IH
2
J23IH
1
J1K
LLML$A',C
D@
NO
(')
PQRD$S?',6F
T/'<5%!/D3%)8,
%!/D',T/'
'66T/'K
%//
U%'O
"
T/'.U%''VW0K
V'O
N
LLB"E
NO
'66T/'K
LL"E
T/'2.T/'D0K
T/'XO
XQVDQO
/XO
N
<%.0K
%IIO
N
NO
PQR.0
'66%!/D"
T/'K
U%'OLL''%
"
%!/D.U%'VW3
U%'VW0T/'.0K
VO
N
LLB"E
NO
'66%!/D"
T/'K
LL"E
%!/D
2.%!/DD0K
%!/D'O
'QVDQO
'QVDQO
/'O
N
<%.0K
T/'.0O
%IIYZYIIO
N
NO
PQR.<50
!'.0K
T/'D3S.RWQ[03X.[Q[0O
DVSQ2.X0O
%IIYDVYODQ.0O
%II/O
%!/D3.[3\03/.\3]0O
VQ2./0O
%IIYVYOQ.0O
%II/O
/
6S6/!.Y2^_HY03H`a*b_^H__O
N
(c#&S
*)'<55!#%
( !)'
*'@S%BE3%5!main
8)F-A'#,Real<5ComplexQ
)F-5S)>85!5<EPrint()
8'!6F)9'A')F-Q
d%)835!main :"%Print %
)F-3SE9eA'G
)F-)>f5!Print )9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