Saturday, July 11, 2015

Program for Auto Generation of Employee ID & Creating 5 Objects

class Employee{
static int noOfObjects=0;
int id;
String name;
double salary;

Employee(String name, double salary){
this.id = noOfObjects;
this.name = name;
this.salary= salary;
noOfObjects++;
}
void print(){
System.out.println("Emp Details\n--------------\n"+this.id+"\t"+this.name+"\t"+this.salary);
}

}
class TestEmployee{
public static void main(String[] args){
Employee e1 = new Employee("Abcd", 12000);
Employee e2 = new Employee("Efgh", 2000);
                Employee e3 = new Employee("Qwert", 14000);
                Employee e4 = new Employee("Poioi", 19000);
                Employee e5 = new Employee("dfsdfsfs", 22000);

e1.print();
e2.print();
                e3.print();
                e4.print();
                e5.print();
}
}

No comments:

Post a Comment