Submit Search
Upload
เมธอด
•
Download as PPTX, PDF
•
0 likes
•
25 views
ก
กฤษดา จันทร์ชาวใต้
Follow
ความรู้เกี่ยวกับเมธอด
Read less
Read more
Technology
Report
Share
Report
Share
1 of 10
Download now
Recommended
เมธอด
เมธอด
Pannipa Saetan
4
4
Fern Pankaew
เมธอด กลุ่ม3
เมธอด กลุ่ม3
Piyada Petchalee
Computer Programming 4
Computer Programming 4
Saranyu Srisrontong
Test File Management System
Test File Management System
Chayanee Junplong
switch case
switch case
Naruemon Soonthong
9789740329923
9789740329923
CUPress
Chapter3
Chapter3
Parkae' Kusuma
Recommended
เมธอด
เมธอด
Pannipa Saetan
4
4
Fern Pankaew
เมธอด กลุ่ม3
เมธอด กลุ่ม3
Piyada Petchalee
Computer Programming 4
Computer Programming 4
Saranyu Srisrontong
Test File Management System
Test File Management System
Chayanee Junplong
switch case
switch case
Naruemon Soonthong
9789740329923
9789740329923
CUPress
Chapter3
Chapter3
Parkae' Kusuma
66
66
Parkae' Kusuma
Method
Method
Latcha MaMiew
Power point
Power point
Pookie Pook
นำเสนอMethods
นำเสนอMethods
FP Spongpoyam
นำเสนอMethods
นำเสนอMethods
FP Spongpoyam
5.Methods cs
5.Methods cs
UsableLabs
งานนำเสนอ1
งานนำเสนอ1
Art Patiwat YourJust'one
คำถามท้ายบท
คำถามท้ายบท
Jiraporn Chaijaroen
Methods
Methods
Yongyut Nintakan
เมธอด กลุ่ม3
เมธอด กลุ่ม3
Mook Prapasson
โจทย์ Pbl3
โจทย์ Pbl3
Nopparat Anusong
โจทย์ Pbl3
โจทย์ Pbl3
Nopparat Anusong
โจทย์ Pbl3
โจทย์ Pbl3
anusong
งานกลุ่มคอมกลุ่ม5
งานกลุ่มคอมกลุ่ม5
Boss'Thanasit Tassana
พื้นฐานภาษาจาวา
พื้นฐานภาษาจาวา
Aeew Autaporn
คู่มือการใช้งานโปรแกรม CourseLab
คู่มือการใช้งานโปรแกรม CourseLab
อาคม สุวรรณประเสริฐ
Java-Chapter 12 Classes and Objects
Java-Chapter 12 Classes and Objects
Wongyos Keardsri
Java Programming [4/12] : Object Oriented Concept
Java Programming [4/12] : Object Oriented Concept
IMC Institute
More Related Content
Similar to เมธอด
66
66
Parkae' Kusuma
Method
Method
Latcha MaMiew
Power point
Power point
Pookie Pook
นำเสนอMethods
นำเสนอMethods
FP Spongpoyam
นำเสนอMethods
นำเสนอMethods
FP Spongpoyam
5.Methods cs
5.Methods cs
UsableLabs
งานนำเสนอ1
งานนำเสนอ1
Art Patiwat YourJust'one
คำถามท้ายบท
คำถามท้ายบท
Jiraporn Chaijaroen
Methods
Methods
Yongyut Nintakan
เมธอด กลุ่ม3
เมธอด กลุ่ม3
Mook Prapasson
โจทย์ Pbl3
โจทย์ Pbl3
Nopparat Anusong
โจทย์ Pbl3
โจทย์ Pbl3
Nopparat Anusong
โจทย์ Pbl3
โจทย์ Pbl3
anusong
งานกลุ่มคอมกลุ่ม5
งานกลุ่มคอมกลุ่ม5
Boss'Thanasit Tassana
พื้นฐานภาษาจาวา
พื้นฐานภาษาจาวา
Aeew Autaporn
คู่มือการใช้งานโปรแกรม CourseLab
คู่มือการใช้งานโปรแกรม CourseLab
อาคม สุวรรณประเสริฐ
Java-Chapter 12 Classes and Objects
Java-Chapter 12 Classes and Objects
Wongyos Keardsri
Java Programming [4/12] : Object Oriented Concept
Java Programming [4/12] : Object Oriented Concept
IMC Institute
Similar to เมธอด
(18)
66
66
Method
Method
Power point
Power point
นำเสนอMethods
นำเสนอMethods
นำเสนอMethods
นำเสนอMethods
5.Methods cs
5.Methods cs
งานนำเสนอ1
งานนำเสนอ1
คำถามท้ายบท
คำถามท้ายบท
Methods
Methods
เมธอด กลุ่ม3
เมธอด กลุ่ม3
โจทย์ Pbl3
โจทย์ Pbl3
โจทย์ Pbl3
โจทย์ Pbl3
โจทย์ Pbl3
โจทย์ Pbl3
งานกลุ่มคอมกลุ่ม5
งานกลุ่มคอมกลุ่ม5
พื้นฐานภาษาจาวา
พื้นฐานภาษาจาวา
คู่มือการใช้งานโปรแกรม CourseLab
คู่มือการใช้งานโปรแกรม CourseLab
Java-Chapter 12 Classes and Objects
Java-Chapter 12 Classes and Objects
Java Programming [4/12] : Object Oriented Concept
Java Programming [4/12] : Object Oriented Concept
เมธอด
1.
เมธอด (Method)
2.
เมธอด (Method) คือ
ความสามารถในการทางานของออบเจ็กต์มันถูกสร้างขึ้นมาพร้อมกับ การสร้างออบเจ็กต์ซึ่งออบเจ็กต์ที่สร้างจากคลาสเดียวกันก็จมมีรายการของเมธอดตาาง เมมือนกัน โครงสร้างทั่วไปของ Method จากโครงสร้างจมเม็นวาาโปรแกรมมนึ่งอาจมีมลาย Class แลมในมนึ่ง Class จมมีกี่ Method ก็ได้แตาใน Class มลัก(Classที่มีpublicนามน้า) จมต้องมี main Method เสมอ
3.
ประเภทของเมธอด (Type of
Method) จาแนกmethodใน Java ได้2ปรมเภทได้แกา Method ที่สร้างขึ้นมาเองแลม Method ที่ มีอยูาแล้วซึ่งแตาลมปรมเภทมีลักษณมดังนี้ 1.Method ที่สร้างขึ้นมาเองสามารถจาแนกmethodที่สร้างขึ้น เอง ได้ดังนี้ 1.1 Methodไม่รับและไม่ส่งค่า เป็น method ที่ไมามีตัวแปรparameterดังนั้นภายใน body ของ method ชนิดนี้จึง ปรมกอบไปด้วย statement ที่ต้องการใม้ทางานเทาานั้นซึ่งมน้าชื่อเมธอดจมมีคาวาา void แลมภายในเมธอดจมไมามีคาวาา return ยกตัวอยาางโปรแกรมงาาย ที่ไมามีความซับซ้อนเพื่องาาย ตาอความเข้าใจดังนี้
4.
ตัวอย่างโปรแกรม : การเรียกใช้
method ในการขีดเส้น Source Code: output //NRandS.java public class NRandS { public static void main(String[] ar) { line(); System.out.println("Hello World!"); }//end main() public static void line() { for (int i=1;i<=20 ;i++ ) { System.out.print("="); }//end for System.out.println(" "); } //end method line() }//end class
5.
1.2 Method ที่มีการส่งหรือคืนค่ากลับ เป็น
method ที่ไมามีตัวแปร parameter แตาเมื่อสิ้นสุดการทางานของ method จมทา การ return กลับไปยัง method เมื่อถูกเรียกใช้งานข้างมน้าชื่อเมธอดจมไมามีคาวาา void แตาชนิดของ dataType ที่ต้องการคืนคาากลับแลมภายในเมธอดจมมีคาวาา return ตัวอย่างโปรแกรม : การ return ค่าตัวแปรเพื่อแสดงผลสูตร คูณแม่ 2 และ 3 มมายเมตุ : เมธอดที่ไมามีการสางคาาผาานเข้าไปในเมธอด ซึ่งมีรูปแบบ ชื่อเมธอด() จมเรียกการเรียกใช้เมธอดปรมเภทนี้วาา Pass by reference
6.
1.3. Method ที่มีการรับค่าหรือมีการนาค่าเข้าสู่ภายในเมธอดโดย ผ่านทาง
parameter ซึ่งมีรูปแบบของการเขียนดังนี้ ชื่อเมธอด(dataType Parameter, dataType Parameter, …) เชาน add(int a, int b) ตัวอย่างโปรแกรม : class add2Num { public void add(int a,int b) { System.out.println(a+b); } //end method ann() public static void main( String args[] ) { add2Num a=new add2Num(); a.add(10,1); // call method ann() } //end main() } //end class
7.
ในการเขียนโปรแกรมสิ่งที่จาเป็นต้องพิจารณาคือ Parameter แลม
Argument โดยที่คาาที่ class มรือ วัตถุนั้นเก็บเพื่อสางตาอใม้กับ Method นั้นคือ Argument สิ่งที่ Method นั้นเก็บจมเรียกวาา Parameter ซึ่งการใช้งานแบบนี้จมเรียกวาา Pass by value จากโปรแกรมที่ผาานมาจมเม็นได้วาา Argument คือ 10 แลม 1 สาวน Parameter คือ a แลม b 1.4. Method ที่มีทั้งการรับค่าและส่งค่า เช่น class add2Num { public int add(int a,int b) { int c = a+b; return c; } //end method ann() public static void main( String args[] ) { add2Num a=new add2Num(); System.out.println(a.add(10,1)); // call method ann() } //end main() } //end class
8.
2. Method ที่มีอยู่แล้ว Method
ชนิดนี้มีอยูาแล้วใน class library พร้อมถูกเรียกใช้งานแตาจมแยกเป็น Method ของ Class แลม Method ของ Object โดยจาแนกได้2ลักษณม ดังนี้ - Method ของ Class (Class Method ) จมเป็น method แบบ Static สามารถเรียกใช้ ได้ทันทีโดยไมาจาเป็นต้องสร้าง Object ใมมาขึ้นมา ดังตัวอยาาง System.out.println(“ “); เมื่อ System คือ ชื่อ class จาก Library Out คือ ชื่อ Object ของ class println() มรือ print คือ ชื่อ Method
9.
-Method ของ Object
(Instance Method) คือ Method ทั่วไปที่มีอยูาใน class แตาเมื่อต้องการ เรียกใช้งานจมต้องสร้าง Object ขึ้นมากาอนแล้วใช้ Object นั้นในการเข้าถึง method Syntax : การใช้ Object เข้าถึง Method ใม้เชื่อมด้วยเครื่องมมาย ( . ) ชื่อ Object . ชื่อ Method( ); การเรียกใช้ Method (Call Method) เนื่องจากการสร้าง method นั้นจมต้องสร้างไว้ภายนอก body ของ method main() ซึ่งเป็น method มลักในการเริ่มทางานของโปรแกรมดังนั้นการเรียกใช้ method ที่สร้างขึ้นจมต้องถูกเรียกภายใน method main() โดยใช้ syntax ดังนี้
10.
1. ในกรณีที่เป็น static
method มรือ เมธอดที่ไมาจาเป็นต้องสร้างวัตถุมาเรียกใช้จมมีรูปแบบการ เรียกใช้เมธอด 2. ในกรณีที่ไมาเป็น static method มรือ เมธอดที่จาเป็นต้องสร้างวัตถุมาเรียกใช้จมมีรูปแบบการ เรียกใช้เมธอด แนะนาคลาส math และเมธอดทางคณิตศาสตร ์ คลาส Math คือ ชนิดข้อมูลพื้นฐานที่เป็นตัวเลข เชาน int มรือ double นั้นสามารถนามาคานวณได้ ภาษาจาวามีคาสั่งสามรับการคานวณงาาย เชาน การบวก การลบ การคูณ แลมการมารซึ่งสามรับการ คานวณที่ซับซ้อนขึ้น เชาน คานวณตรีโกณมิติ ล็อกการิทึมนั้นภาษาจาวาก็ทาได้ เชาน กันโดยใช้คลาส Math ชาวยในการคานวณ
Download now