modifiers for these variables.
Instance variables can be gotten to by calling the variable name inside the class.
The
following
statement
can
be
used
for
this
purpose:
Objectreference.variablename.
Sample Implementation:
import java.io.*;
public class Employeerecord{
public String empname;
private
double empcompensation;
public Employee (String name){
empname = name;
}
public void initsalary(double empsalary){
empcompensation = empsalary;
}
public void printemployee(){
System.out.println(“Employee name : ” + empname );
System.out.println(“Employee salary :” + empcompensation);
}
public static void main(string args[]){
Employeerecord employee1 = new Employeerecord(“Mary”);
employee1.initsalary(7500);
employee1.printemployee();
}
The compilation and execution would deliver the accompanying result:
Employee name : Mary
Employee compensation :7500.0