سلام عليكم
عندي سؤال ياخوان
// Fig. 3.4: GradeBook.java
2 // Class declaration with a method that has a parameter.
3
4 public class GradeBook
5 {
6 // display a welcome message to the GradeBook user
7 public void displayMessage( String courseName )
8 {
9 System.out.printf( "Welcome to the grade book for\n%s!\n",
10 courseName );
11 } // end method displayMessage
12
13 } // end class GradeBook
هذا في ملف ثاني
4 import java.util.Scanner; // program uses Scanner
5
6 public class GradeBookTest
7 {
8 // main method begins program execution
9 public static void main( String args[] )
10 {
11 // create Scanner to obtain input from command window
12 Scanner input = new Scanner( System.in );
13
14 // create a GradeBook object and assign it to myGradeBook
15 GradeBook myGradeBook = new GradeBook();
16
17 // prompt for and input course name
18 System.out.println( "Please enter the course name:" );
19 String nameOfCourse = input.nextLine(); // read a line of text
20 System.out.println(); // outputs a blank line
21
22 // call myGradeBook's displayMessage method
23 // and pass nameOfCourse as an argument
24 myGradeBook.displayMessage( nameOfCourse );
25 } // end main
26
27 } // end class GradeBookTestليه الملف الاول في ال method كاتب courseName اش استفيد منه
وليه في املف الثاني غير المتغير ليه ماحط المتغير الاول الى هو courseName
myGradeBook.displayMessage( nameOfCourse );
هذا المتغير اش استفيد منه nameOfCourse
وشكراً لكم
