There are six variable types in Java: class variables, instance variables, method parameters, constructor parameters, exception processor parameters, and local variables. - Class variable class variable: Static data members declared in the class and data members declared in the interface. - Example Variable Instance Variable: Nonstatic variables declared in the class. - Method parameters Method Parameter: It is used to pass a method body. - Constructor Parameters Constructor Parameter: Used to pass a constructor. - Exception Handler Parameter: Used to pass it in a Catch block of a TRY statement. - Local variable Local variable: Variables declared in a code block or in the for statement.
The example is illustrated as follows:
Public class javavariables {
// Class Variable class variable public static string classvariable = "this is a class variable."
// Instance Variable instance variable private string instancevariable = "this is an instance variable.";
// Constructor variable constructor PUBLIC JAVAARIABLE (STRING Constructorpara) {}
// Method Parameter method Parameters Public void sampleMethod (String methodpara) {
// local variable local variable string localvariable = "this is a local variable";
Try {
// Exception parameter} catches (Exception Exceptionpara) {}
}
}