class WorkerDetail
{
int c,s;
String n;
float h;
void SetSalary(int x, String y, int z)
{
c=x;
n=y;
s=x;
}
void ShowDetail()
{
System.out.println("Code : "+ c);
System.out.println("Name : "+n);
System.out.println("Salary : "+s);
}
void getHra()
{
h=(float)s*60/100;
System.out.println("HRA : "+h);
}
}
class officerDetail extends WorkerDetail
{
float d,g;
void getda()
{
d=(float)s*98/100;
System.out.println("DA : "+d);
}
void getGross()
{
g=s+h+d;
System.out.println("Gross : "+g);
}
};
class ExInheritance
{
public static void main(String args[])
{
WorkerDetail wD = new WorkerDetail();
officerDetail oD = new officerDetail();
wD.SetSalary(121,"Aman",13000);
oD.SetSalary(111,"Amrik",30000);
System.out.println("Detail of Worker is :");
wD.ShowDetail();
wD.getHra();
System.out.println("Detail of Officer is :");
oD.ShowDetail();
oD.getHra();
oD.getda();
oD.getGross();
}
};
Dinesh Thakur holds an B.SC (Computer Science), MCSE, MCDBA, CCNA, CCNP, A+, SCJP certifications. Dinesh authors the hugely popular Computer Notes blog. Where he writes how-to guides around Computer fundamental , computer software, Computer programming, and web apps. For any type of query or something that you think is missing, please feel free to Contact us.
Search Content
Popular Article
Basic Courses
Advance Courses