เมธอด ชั้น ม 6 ห้อง 2

240 views

Published on

0 Comments
0 Likes
Statistics
Notes
  • Be the first to comment

  • Be the first to like this

No Downloads
Views
Total views
240
On SlideShare
0
From Embeds
0
Number of Embeds
3
Actions
Shares
0
Downloads
7
Comments
0
Likes
0
Embeds 0
No embeds

No notes for slide

เมธอด ชั้น ม 6 ห้อง 2

  1. 1. method
  2. 2. MethodFunctionMethod Method Java
  3. 3. Class Class MethodClass Class publicmain Method
  4. 4. Method modifiers public staticReturn_ Type voidMethodNameparameter (;)reture
  5. 5. (Type of Method)1. Static Method -2. Instance Method -3. Constructor Method -4. Overloading Method -5. Overriding Method -1. Static Method static method(argument);
  6. 6. 2. Instance Methodobject.method(argument);object.attribute3. Constructor Method constructor voidClass object = new Class();
  7. 7. 4. Overloading Method overload constructor)Overloading Methodpublic int Print(int idbook){...}public String Print(int bookname){...}Overloading Constructorpublic Circle() {...}public Circle(int radius) {...}Output Student
  8. 8. 5. Overriding Method Inheritance)class Person { public void print() {System.out.print("People");}}class Student extend Person { public void print() {System.out.print("Student");}}
  9. 9. main()static displayMessage() SimpleMethod.java
  10. 10. main
  11. 11. hierarchical A B B C C JVM B JVKA
  12. 12. DeepAndDeeper.java
  13. 13. Math void
  14. 14. sqfrt 16 4 area Math APIMath.pow
  15. 15. Math .pow double 4.0 2.0 3 6 3
  16. 16. 4.0 2.0 3 6 3Math.sqrt doble 3.0
  17. 17. Math.random 0 1
  18. 18. MathDemo.java Math Random 0.0 1.0 10
  19. 19. TenRandomNumber.java 10 1 6
  20. 20. random r r 0.0 1.0 6.0 1.0 7.0
  21. 21. (argument) (parameter) parameter_list PrintCharLine PrintLine cchar len int clen
  22. 22. 1: using System;2: class ParamNoRet {3: static void PrintCharLine(char c, int len){4: for (int i = 0; i < len; i++)5: Console.Write(c);6: Console.WriteLine();7: }8:9: static void Main() {10: PrintCharLine(’o’, 10);11: PrintCharLine(’x’, 20);12: }13: }
  23. 23. PrintCharLine Main 10 o 10PrintCharLine c len 4 5 o 10 PrintCharLine 11 x 20
  24. 24. 4.4 showSum void return showSum
  25. 25. total double
  26. 26. 3 4showSum return Add
  27. 27. = -32 1.8double double
  28. 28. (true) (false)boolean 1 100
  29. 29. main main 4.8 4.8 f(x)= x2 5 x 0 10
  30. 30. return
  31. 31. 4.9 2 1isPrimereturn 5
  32. 32. 6317 7163
  33. 33. 4.5 Local (local variable) 4.10 main() Phuket rayong birds 4.10LocalVars.java
  34. 34. 4.10
  35. 35. 4.11x main x one() x main x one x main 4.11Local2.java
  36. 36. 4.6 (Overloading Method) (OverloadMethod) 4.12 4.12
  37. 37. 4.13 CalGrade.java 75
  38. 38. 4.14 BarChart.java Bar*
  39. 39. 24
  40. 40. 1 282. 293. 324. 335. 346.

×