class Rectangle Rectangle nint number Of Bikes nfloat
ตวอยาง class Rectangle{ } Rectangle
ตวอยางประกาศคาตวแปร nint number. Of. Bikes; nfloat tax. Rate; ndouble interests, PI; nboolean yes. Or. No; nchar response;
ตวอยางประกาศคาตวแปร nint number_of_bikes; nfloat tax_rate; ndouble cum_gpa; nboolean yes_or_no;
ตวอยาง class Rectangle{ double width; double height; }
ตวอยาง class Rectangle{ double width; double height; double get. Area(){ return width*height; } }
class Rectangle{ ตวอยาง double width; double height; double get. Area(){ return width*height; } void set. Area(double w, double h){ width=w; heigth=h; } }
class ชอคลาส attribute 1; attribute 2; method 1(){ //วธการทำงาน } method 2(){ //วธการทำงาน } } { attribute method
class Rectangle{ ตวอยาง double width; double height; double get. Area(){ return width*height; } void set. Area(double w, double h){ width=w; heigth=h; } }
class Rectangle{ ตวอยาง double width; double height; double get. Area(){ return width*height; } void set. Area(double w, double h){ width=w; heigth=h; } }
การแสดงผลขอมลออกทางจอภาพ Method ชอ print, println ของ Class out อยในแพกเกจ System. out. print(data) System. out. println(data) System. out. print(“This is text”); System. out. print(“This is : : : ”+x);
Rectangle rec; rec null stack Heap
rec = new Rectangle(); Rectangle width=0. 0 new Rec tan gle( ); height=0. 0 rec 0 x 02 AB 257 stack Heap
Rectangle rec = new Rectangle(); Rectangle width=0 new Rec tan gle( ); height=0 main } rec 0 x 02 AB 257 stack Heap
Rectangle rec 1 = new Rectangle(); Rectangle rec 2 = new Rectangle(); Rectangle width height new main } rec 2 0 x 02 AB 334 rec 1 0 x 02 AB 257 stack (); e l ng a ct e R new Rectangle ; ) ( e l g n Recta width height Heap
0. 0 new Rectangle(). width=3. 0; System. out. println("คาของ Width คอ "+new Rectangle(). width); new Rectangle() width=3. 0 height new Rectangle() main width height } stack Heap
Rectangle rec=new Rectangle(); System. out. println("คาของ Width คอ "+rec. width); rec. width=3. 0; System. out. println("คาของ Width คอ "+rec. width); e main } R new ; () e l g ctan width =3. 0 heigth rec 0 x 02 AB 257 stack Heap 0. 0 3. 0
Rectangle rec 1=new Rectangle(); 3. 0 System. out. println("คาของ Width คอ "+rec 1. width); Rectangle rec 2=new Rectangle(); System. out. println("คาของ Width คอ "+rec 2. width); 0. 0 rec 1. width=3. 0; new Rec tan gle (); width heigth } main rec 2 0 x 02 AB 247 rec 1 0 x 02 AB 244 stack new ); ( e l g n Recta width =3. 0 heigth Heap
Rectangle rec 1 = new Rectangle(); Rectangle rec 2 = new Rectangle(); rec 2=rec 1; ตวอยาง Rectangle ngl e(); width height new Re cta Rectangle } main rec 2 0 x 02 AB 257 0 x 02 AB 334 rec 1 0 x 02 AB 257 stack () e l g n ta c e R ew ; width height n Heap
Rectangle rec 1 = new Rectangle(); Rectangle rec 2 = new Rectangle(); rec 2=null; ตวอยาง Rectangle ngl e(); width height new Re cta Rectangle } main rec 2 0 x 02 AB 334 null rec 1 0 x 02 AB 257 stack new () e l g n Recta ; width height Heap
Rectangle rec=new Rectangle(); System. out. println("คาของ Width คอ "+rec. width); System. out. println("คาของ Width คอ "+rec. height); } main new ; ta c e R ) ( e l ng width = 0. 0 heigth = 0. 0 rec 0 x 02 AB 257 stack Heap
Rectangle rec=new Rectangle(); width*heigth 0. 0 * 0. 0 System. out. println("คาของ Width คอ "+rec. get. Area()); width=0 heigth=0 h t g i e h*h get. Area } } main widt ); ( e l g ctan e R w ne return rec 0 x 02 AB 257 stack Heap
width*heigth Rectangle rec=new Rectangle(); 0. 0 * 0. 0 System. out. println("คาของ Width คอ "+rec. get. Area()); double area=rec. get. Area(); System. out. println("คาของ Width คอ "+area); 0. 0
} }} class Scope. Example{ this int i=2; second. Method 10 y void first. Method(){ x int i=9, j=3; 4 this. i=i+j; this second. Method(4); 3 first. Method j } i 9 void second. Method(int x){ int y=10; scope 0 x 02 AB 233 main this. i=x+y; stack } public static void main(String [] arg){ Scope. Example scope=new Scope. Example(); scope. first. Method(); System. out. println(scope. i); } } 4+ 10 9+3 c S w e n a Ex e p o (); le mp i 14 2 12 Heap
[modifier] ทไดรจกวนน q. Class q. Attribute q. Method final, static
- Slides: 80