System.out.println();

               DifferentKindsOfVariables objectReference_Student2 = new DifferentKindsOfVariables("Santa claus");

                objectReference_Student2.setGrade(95,88,93);

                objectReference_Student2.display();

                System.out.println("To call a static field " + DifferentKindsOfVariables.staticVariable_StudentNumber);

          }

}

----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

There are different kinds of variables. The fields, local and the parameter. The fields are composed of non static and the static variable. First let us discuss the local variable. This "double localVariable_x;" inside the display method is a local variable. It is used exclusively inside the method. It cannot be access by other methods even though they do have the same class. double is the variable type. it is a primitive type with a range greater than a float and integer. You can check the other primitive types and their range on the internet. localVariable_x is the variable name followed by a semi-colon. This localVariable_x should be initialize. Initializing means giving a default value to the variable. Next is the Parameter. This "int parameter_Prelim, int parameter_Midterm, int parameter_Endterm" inside the parenthesis of a method called setGrade are called parameters; int is the variable type which means integer.  Others called it arguments but as i understand it, they are just the same except that when these parameters received a value they are referred to as arguments. The usage of these parameters is to received a value from the object that calls the method. They called it as pass by value. Third is the non static field. This "private double instanceVariable_FinalGrade;" is just one of the non static field. Usually they call this as instance variable. Because there value is unique to each object of the class. That means that each object has  their own value. Note that when they refer to instance, they are referring to the object of the class.  Last is the static field. This "private static int staticVariable_StudentNumber;" is a static field. Obviously because of the static keyword in the declaration of the variable.  Static means that there is only one copy of this variable no matter how many objects that class creates. In the program, you can call the non static using the object you create from the class like this "objectReference_Student1.instanceVariable_FinalGrade" while the static field can be invoke using the class name since it is a class variable and not just an object variable like the non static like this "DifferentKindsOfVariables.staticVariable_StudentNumber". 

HOW DO WE READ THESE PROGRAM?

We created an object named "objectReference_Student1"and "objectReference_Student2"from the class "DifferentKindsOfVariables". We used this object to call two methods which is setGrade() and display(). setGrade() has three parameters which is the "parameter_Prelim", "parameter_Midterm", "parameter_Endterm" that is equaled to the instance variables "instanceVariable_PrelimGrade", "instanceVariable_MidtermGrade", "instanceVariable_EndtermGrade" respectively. The value of these non static fields are used to compute the "instanceVariable_FinalGrade" in the getGrade() method. Then, after the setGrade(), we call the display() method. In here, we print out the "instanceVariable_FinalGrade" using the println method in the "System.out" class, by calling the getGrade() method inside its parenthesis. Then, we used an if else statement to test the "instanceVariable_FinalGrade" if it is greater than 75 or not. If it is, then the student passed otherwise the student failed. The if-else statement is one of the basic control flow statement of the java language. We will discussed more of this hopefully if i can remember.

Java codes i learned onlineOnde histórias criam vida. Descubra agora