/****************************************************************************
 * Employee class (to test access of fields/methods within the same class)
 ***************************************************************************/
class Employee
{
    static String companyName  = "XYZ inc.";            //static fields
    static int    employeeCount;
    
    String lastname;                                    //instance fields
    String firstname;

    Employee(String first, String last)                 //constructor
    {
        firstname = first;
        lastname  = last;
        employeeCount++;
    }
    
    static int getEmployeeCount( )                                      //static method
    {
        return (employeeCount);
    }

    String getFullname(String sal)                                      //instance method
    {
        return(sal + " " + firstname + " " + lastname);
    }

  //- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 
    static void companyInfo( )                                        //static method
    {
        System.out.println("Company: "   + companyName);                     //OK - accessing static field 
        System.out.println("Company: "   + Employee.companyName);            //OK

        System.out.println("Emp count: " + getEmployeeCount() );            //OK - accessing static method
        System.out.println("Emp count: " + Employee.getEmployeeCount() );   //OK

//      System.out.println("Firstname: " + firstname);                      //Not OK accessing instance field
//      System.out.println("Fullname:  " + getFullname("Mr.") );            //Not OK

    }
  //- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 
    public String toString()                                          //instance method
    {
        String data = "\n Company: "   + companyName                        //OK - accessing static field
                    + "\n Company: "   + Employee.companyName               //OK
                    + "\n Company: "   + this.companyName                   //OK

                    + "\n Emp count: " + getEmployeeCount( )                //OK - accessing static method
                    + "\n Emp count: " + Employee.getEmployeeCount( )       //OK
                    + "\n Emp count: " + this.getEmployeeCount( )           //OK

                    + "\n Firstname: " + firstname                          //OK - accessing instance field
                    + "\n Firstname: " + this.firstname                     //OK

                    + "\n Fullname: "  + getFullname("Mr.")                 //OK - accessing instance method
                    + "\n Fullname: "  + this.getFullname("Mr.");           //OK

        return(data);
    }
  //- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 
}



/*******************************************************************************
 * Employee user class (to test access of fields/methods of another class) 
 ******************************************************************************/
public class EmployeeBuild
{
    public static void main (String[ ] args)
    {        


    //- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 
    //Before creation of object 

        System.out.println(Employee.employeeCount);             //OK - accessing static field
        System.out.println(Employee.getEmployeeCount());        //OK - accessing static method

//      System.out.println(Employee.lastname);                  //Not OK - accessing instance field
//      System.out.println(Employee.getFullname("Mr."));        //Not OK - accessing instance method


    //- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 
    //Creating an object 

        Employee emp = new Employee("John", "Smith");           //call the constructor
        

    //- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 
    //After creation of object 

        System.out.println(Employee.employeeCount);             //OK - accessing static field
        System.out.println(Employee.getEmployeeCount());        //OK - accessing static method

        System.out.println(emp.employeeCount);                  //OK - I can even access using the object name
        System.out.println(emp.getEmployeeCount());             //OK 

        System.out.println(emp.firstname);                      //OK - accessing instance field
        System.out.println(emp.getFullname("Mr."));             //OK - accessing instance field

    //- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 
   }
}