Lập trình hướng đối tượng trong java (Phần 2) - Pdf 18










1
LẬP TRINH HƯỚ NG ĐÔ
́
I TƯỢNG TRONG JAVA
phần 2

IV.  

A

1. Khai ba
́
o kế thư
̀
a




 






 








 


- 

 





(SuperClass : )
- 

 







 





-   











 
 



 .   










 ,  




 













 , 


 



.
V d :  











 . L
toString,  .   




  







 





 






 . 



 

, 
 





. 











 ,
 







 




cha c: classname()
:
super(Parameter-List)
Parameter-



  .
super() 
con
:
class MyPoint {

}
void display() { // Vi
         
\
}
}
- 2 : :
super.Member








 

 
: 

() trong class MyPoint2, c:
void display() {
super.display();
\
}

V.  , PH    



  













  .


,  . 




 , 


abs



 







 . 

 

 






 ,  . 

,
 .  















 (, )
 nh vi (

, 



 , ). 
Graphic. 
























4
abstract class GraphicObject {
int x, y;
. . .
void moveTo(int newX, int newY) {
. . .
}
abstract void draw();
}








 ircle, 



class Circle extends GraphicObject {
void draw() {

  







 


Java, 



   

 . 

 




  , 

: class Box {
double width;
double height;
double depth;







 

, .




, .














 






 
(Nested Class) :
class EnclosingClass{ // 




. . .
static class StaticNestedClass { // 

 


. . .
}
class InnerClass { // 

 




. . .
}
}





 



 .
: .
L (static nested class) 





 . 
     

  












}
}
void display_y() { // không th

}
}
class InnerClassDemo {
public static void main(String args[]) {
Outer outer = new Outer();
outer.test();
}
}


Nhờ tải bản gốc
Music ♫

Copyright: Tài liệu đại học © DMCA.com Protection Status