Read employee number and salary (exercise to use static keyword) WAP to create a class called Employee having empid and salary as data members and salary as data members. Create objects of this class and count no. of employees working in an organization using static keyword.

This is my solution for the above question. Is it correct way of doing this? I am a beginner so I would appreciate your help. Let me know of my mistakes. 

    import java.util.*;
    class Employee{
private int empid;
private int salary;
private static int count;

private void setValue(int empid,int salary){
this.empid=empid;
this.salary=salary;
count++;
}

private void getValue(){
System.out.println("EmpId = "+empid);
System.out.println("Salary ="+salary);
System.out.println("Number of employees: = "+count);
}

public static void main(String[] args)
{
    Scanner kb=new Scanner(System.in);
    Employee e=new Employee();
    int id,sal;
    System.out.println("Enter Employee Id: ");
    id=kb.nextInt();
    System.out.println("Enter Salary: ");
    sal=kb.nextInt();
    System.out.println("The Values entered are :");
    e.setValue(id,sal);
    e.getValue(); 
    Employee e1=new Employee();
    System.out.println("Enter Employee Id: ");
    id=kb.nextInt();
    System.out.println("Enter Salary: ");
    sal=kb.nextInt();
    System.out.println("The Values entered are :");
    e1.setValue(id,sal);
    e1.getValue();
}}
No.

You use a setter to modify an existing employee. But it makes no sense to change the id and salary together. In fact, you should never change the id of an employee.

This should be the constructor of the class instead. In your main I would expect to see the folowing flow:

Scanner kb=new Scanner(System.in);
int id,sal;
System.out.println("Enter Employee Id: ");
id=kb.nextInt();
System.out.println("Enter Salary: ");
sal=kb.nextInt();
System.out.println("The Values entered are :");
Employee e=new Employee(id, sal);


A second thing to note is that a method with prefix "get" is expected to return some value of the object. Either rename that getValue() method to something like printInfo() or provide actual getters:

public String getId() {
    return id;
}

public static int getNbOfEmployees(){
    return count;
}


These can then be used somewhere else to print out the info, for example in your main:

System.out.println("EmpId = " + e.getId());
System.out.println("Salary =" + e.alary());
System.out.println("Number of employees: = " + Employee.getNbOfEmployees());