Write a Java Program to implement array of objects. 

Program Code:
import java.lang.*;
public class EmployeeTest
{
public static void main(String[] args)
{
Employee[] staff = new Employee[3];
staff[0] = new Employee("Mukesh Rajput", 7500);
staff[1] = new Employee("Ravi Kant", 8500);
staff[2] = new Employee("Rahul Sharma", 6500);
for (int i = 0; i < 3; i++)
staff[i].print();
}
}
class Employee
{
private String name;
private double salary;
public Employee(String n, double s)
{

name = n;
salary = s;
}
public void print()
{
System.out.println(name + " " + salary);
}
}

Output:
Mukesh Rajput 7500.0
Ravi Kant 8500.0
Rahul Sharma 6500.0
Mukesh Rajput

Mukesh Rajput

I am a Computer Engineer, a small amount of the programming tips as it’s my hobby, I love to travel and meet people so little about travel, a fashion lover and love to eat food, I am investing a good time to keep the body fit so little about fitness also..

Post A Comment:

0 comments: