วันพุธที่ 8 มีนาคม พ.ศ. 2560

สรุป OOP

สรุป OOP

[<public>,<final>]Class <class name>[extends]<class name>{ }
-          Public หมายถึง การเซฟชื่อไฟล์ ตามนั้น
-          Final คือ ไม่สามารถให้สืบทอดได้
ทั้งสอง อย่างสามารถใช้ร่วมกันได้ทั้ง public & final

มีการแบ่งการทำงานโปรแกรมออกเป็นส่วนๆ
เรียกว่า class  การทำงานของมันจะทำผ่าน เมททอด เช่นโค้ดการทำงานในคะแนนย่อย
การทำงานจะทำงานเป็นส่วนๆ ตามคลาส แต่ละคลาสสามารถ ทำงานได้หลายอย่าง คือ มีหลาย เมดตอท ซึ่งการทำงานแต่ละคลาสจะไม่เกี่ยวกับคลาสอื่นๆเลย
                การทำงาน มีการ
Acessmodifier = protecteg,encapsulation,inheritant,polymorphism,final,static




Encapsulation àprivate (method),(value) เป็นการประกาศเมดทอด หรือตัวแปล เป็นการ เอน แคปซูเลชั่น

ตัวอย่างการประกาศ ค่า
1. การประกาศ ตัวแปร  à   <access mo><data type><value name>;
   à    private int var;
2. การประกาศเมดทอต à <acc mo>[static]<return type><method>(<args>,….){ }

Return type คือ การส่งค่ากลับ (int.float,double)หรือ ( void )ไม่คืนค่า
Acessmodifie = protected,private,public
Return type = string,float,double,….,void
[args]  à <data type value name>

Ex
            Protected double testDouble(int x,int y)
{
            Double sum;
Sum=x/y;
Return sum;
หรือ
Return x/y;
            // Return <double value>
}

****ลองดูการประกาศชนิดตัวแปร


Ex.
                Private int varCom(float x){ }



Inheritant 
 การสืบทอด มาจากคลาสอื่น ที่มีคุณสมบัติเหมือนกัน กับคลาสที่สืบทอดมา
            Class super{}
            Class child extends super{}   // extends คือ การสืบทอดแต่สามารถสืบทอดได้ คลาสเดียวเท่านั้น




Polymorphism
            มีได้หลายรูปแบบ เปลี่ยนแปลงรูปร่าง
                คลาสๆหนึ่งสามารถเพิ่มเติมได้หลายอย่าง


Object

<class name><object name> = new<class name>();
เกิด จากคลาสหนึ่ง
Ex1
Class test1{}
Class test2{}
Class test3{
            Test1 obj1 =new test1();
Test2 mom =new test2();
}


Ex2
Class test1{
            Int x;
            Void test(……){}
}
Class test2{
            Float x;
            Void tests(…….){}

}
Class test3{
            Test1 obj1 =new test1();
Test2 mom =new test2();
Obj_1.test();
}
ถ้ามีการส่งค่ามาเพียงตัวเดียวก้อจะทำงานที่ ที่กำหนดเท่านั้น
class compute
{
            private double compute(float x)
}

class input
{
public static void main(args[])
{
Double x,y;
            computer  A = new computer();// สร้าง obj
x=        A.computers(float.parseFloat(args[0]))
y=        A.computers(float.parseFloat(args[0] ),float.parseFloat(args[0]))


}
           
}

ไม่มีความคิดเห็น:

แสดงความคิดเห็น

Set Enable .Net framework 3.5 on windows 10 (ติดตั้ง .Netframework 3.5 บนวินโดวน์ 10)

1. Download windows 8.1 file [ TH : ดาวน์โหลดไฟล์ ของ windows 8.1 ] 2. Mount File windows Copy file \sources\sxs from mount drive ...