A class in java is a user-defined type that describes what a certain type of object will look like. A class description consists of a declaration and a definition. Usually these pieces are split into separate files. An object is a single instance of a class. You can create many objects from the same class type.
class Employee{
int id;
String name;
public void setId(int id) {
this.id = id;
}
public int getId() {
return id;
}
public void setName(String name) {
this.name = name;
}
public String getName() {
return name;
}
}
public class tut9 {
public static void main(String[] args) {
Employee e1 = new Employee();
e1.setId(1);
e1.setName("Employee 1");
System.out.println(e1.getId());
System.out.println(e1.name);
}
}