SAME NAME IN CLASS METHOD AND CONSTRUCTOR
SAME NAME IN CLASS METHOD AND CONSTRUCTOR, STATIC VARIABLE
class Emp
{
String ename;
int age;
int sal;
static int count=0;
int empno;
Emp()
{
}
void Emp(String n, int a, int s)
{
count+=1;
empno=count;
ename=n;
age=a;
sal=s;
}
void show()
{
System.out.println("Emp_no: "+empno);
System.out.println("Emp_name: "+ename);
System.out.println("Emp_age: "+age);
System.out.println("Emp_Salary: "+sal);
}
public static void main(String a[])
{
Emp e1[]=new Emp[5];
for(int i=0;i<5;i++)
{
e1[i]=new Emp();
}
for (int i=0;i< 5 ; i++)
{
e1[i].Emp(("A"+i),(22+i+2),(2000+100*i));
}
for (int i=0;i< 5 ; i++)
{
e1[i].show();
}
}
}
Comments
Post a Comment