Lecture Java programming language: Methods - Ho Dac Hung

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. | Methods Ho Dac Hung 1 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 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 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 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 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 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 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 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 .

Không thể tạo bản xem trước, hãy bấm tải xuống
TÀI LIỆU MỚI ĐĂNG
Đã phát hiện trình chặn quảng cáo AdBlock
Trang web này phụ thuộc vào doanh thu từ số lần hiển thị quảng cáo để tồn tại. Vui lòng tắt trình chặn quảng cáo của bạn hoặc tạm dừng tính năng chặn quảng cáo cho trang web này.