Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- 1.) คลาส คือ
- public class A{
- }
- ----------------------------
- 2.) Fields คือตัวแปรที่ประกาศอยู่บนสุดของ class
- public class A{
- public int a = 0;
- public String b = 0;
- .
- .
- .
- .
- }
- -----------------------------
- 3.) method คือ
- public class A{
- public String hello{ // method hello
- }
- }
- ----------------------------
- 4.) overloading เป็นการเขียน method ใหม่ซึ่งมีชื่อซ้ำกัน แต่ประเภทของ parameter ไม่เหมือนกัน
- public class A{
- public int hello(int a){ // method hello
- }
- public int hello(String a){ // overloading method hello
- }
- }
- ----------------------------
- 5.) constructor คือ method ที่ชื่อเดียวกับคลาส
- public class A{
- public A(){
- }
- }
- -----------------------------
- 6.) การสืบทอดคลาส
- public class A{
- }
- public class B extends A{
- }
- อธิบาย : คลาส B สืบทอด A
- ---------------------------------
- 7.) การสร้าง Instance (ไล่ลำดับการทำงานตามตัวเลข)
- public class HelloWorld{
- public int a = 0;
- public static void main(String[] args){
- HelloWorld h = new HelloWorld(); 1) // สร้าง Instance ของคลาส Hello
- h.my_method(); 2) // เรียกใช้งาน my_method ของคลาส HelloWorld
- }
- public void my_method(){
- int a = 999;
- System.out.println(a); 3) // print a (ไม่ใช้ this จะได้ 999 จากตัวแปรใน local)
- System.out.println(this.a); 4) // print a (ใช้ this.a จะได้ค่า 0 จาก field ของ class)
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement