intTypePromotion=1
zunia.vn Tuyển sinh 2024 dành cho Gen-Z zunia.vn zunia.vn
ADSENSE

Lecture Java programming language: Methods - Ho Dac Hung

Chia sẻ: Trinh _ | Ngày: | Loại File: PDF | Số trang:10

23
lượt xem
2
download
 
  Download Vui lòng tải xuống để xem tài liệu đầy đủ

Methods has main content such as program development using methods, program development using methods, writing methods, method parameters, method overloading, the return statement, documenting methods.

Chủ đề:
Lưu

Nội dung Text: Lecture Java programming language: Methods - Ho Dac Hung

  1. Methods Ho Dac Hung 1
  2. Program Development Using Methods  The solution to a task can be developed by breaking the task down into smaller subtasks. These subtasks can then be reduced to yet simpler task. This problem-solving approach described a software development process called top-doen development. 2
  3. Program Development Using Methods  In top-down development, the first level of subtasks translate into the main() method. Levels of tasks below main() are developed into a series of additional methods. 3
  4. Writing Methods  A method consists of a declaration and a body. The method declaration includes access level, return type, name, and parameters, if any. The method body contains the statements that implement the method. A method takes the form: (){ } 4
  5. Method Parameters  A method declaration can include method parameters, which accept values from the method call. The data passed to the method can then be used inside the method to perform its task. 5
  6. Method Parameters  Data is given, or passed to a method by enclosing the data in parentheses in the method call. The value or variable passed to a method is called the argument. 6
  7. Method Parameters  In Java, arguments are passed by value, which means that the data stored in an argument is pass. An argument that is a primitive data type gives the method a copy of its value. An argument that is an object gives the method a copy of its reference.  When a method declaration includes more than one parameterm the parameters are seperated by commas. 7
  8. Method Overloading  The method declaration is used by the compiler to determine which method is execute. Therefore, methods name do not have to be unique as long as the parameters are different foe methods with the same name.  Method overloading is when more than one method of the same name is included in a class. 8
  9. The return Statement  A method can return a value. The return statement is used to send a value back to the calling statement. A return statement can return only one “value”.  A method that return a value must include the return type in the method declaration. 9
  10. Documenting Methods  Methods should be carefully commented so that a reader of the program understands what task the method is performing and what data, if any, will be returned by the method. Method documentation is in the form of documentation comments. 10
ADSENSE

CÓ THỂ BẠN MUỐN DOWNLOAD

 

Đồng bộ tài khoản
2=>2