Local variables:
Age is a local variable. Defined in the Pubage () method, its scope is limited to this method.
public class Test{public void Pupage () {int = 0; /*age must initialize or error */age = age + 7; System.out.println ("Puppy:" + Age);} public static void Main (String args[]) {test test = new test (); Test.pupage ();}}
Run Result: Puppy Age is 7
Member variables:
Import java.io.*;p Ublic class employee{//This member variable is visible to the public String name;//private variable, only in the class visible private double salary;// Assign a value of public Employee (String empname) {name = EmpName;} to name in the constructor Set the value of salary public void setsalary (double empsal) {salary = Empsal;} Print information public void Printemp () {System.out.println ("name:" + name); System.out.println ("Salary:" + salary);} public static void Main (String args[]) {Employee Empone = new Employee ("Ransika"); empone.setsalary (1000); Empone.printemp ();}}
Running Result: Name:ransika
salary:1000.0
class variables (static variables):
Import java.io.*;p Ublic class employee1{//salary is a static private variable that is a constant public static double salary;//department Final String departement = "Development";p ublic static void Main (String args[]) {salary = 1000; System.out.println (departement+ "average salary:" +salary);}}
Operation Result:
Development Average Salary:
Problem encountered, Java compilation error: Parsing has reached the end of the file?
Resolution: Missing curly braces, search carefully!
Several types of Java variables