Multilevel Inheritance




This  program  is  show  multilevel inheritance . Here  we try to calculate the salary of the
 employee take  command line inputs   of the Employee . We will input  employee details
 and basic salary then  it  calculate  salary details




import java.io.*; 
import java.lang.*;
class emp
{
String ename;
int empno; 
String desig;
void readdata()throws IOException
{

DataInputStream dis=new DataInputStream(System.in);

System.out.println("enter emp name"); 

ename=dis.readLine()
System.out.println("enter empno");
empno=Integer.parseInt(dis.readLine()); 

System.out.println("enter designation");

desig=dis.readLine(); }
}
class basic extends emp {
double bsal;
double da
double hra;
void readbsal()throws IOException {

DataInputStream dis=new DataInputStream(System.in); 
System.out.println("enter basic salary"); 
bsal=Double.parseDouble(dis.readLine());
}
void calhrada() {
da=bsal*0.95;
hra=bsal*0.15
 }
}
class grosssal extends basic
{
 double gsal;
 void display() {
       
    gsal=bsal+da+hra;
   System.out.println("empno: "+empno); 
   System.out.println("empname: "+ename); 

 System.out.println("degnisation: "+desig); 
  System.out.println("basic sal: "+bsal); 
  System.out.println("da: "+da);
  System.out.println("hra: "+hra);
  System.out.println("gross sal: "+gsal);

     }
  }
 class ComputeSalary{
 public static void main(String args[]) throws IOException {
  grosssal g=new grosssal();
     g.readdata();
     g.readbsal();
     g.calhrada(); 
     g.display();
   } 
}

Program out  of this  code  is  calculate salary of an employee when you input  
the basic salary .


enter emp name
Mahadev
enter empno
11123
enter designation
SSO
enter basic salary
30000
empno: 11123
empname: Mahadev
degnisation: SSO
basic sal: 30000.0
da: 28500.0
hra: 4500.0

gross sal: 63000.0


Multilevel Inheritance Multilevel Inheritance Reviewed by Mukesh Jha on 7:11 AM Rating: 5

No comments:

Add your comment

All Right Reserved To Mukesh Jha.. Theme images by Jason Morrow. Powered by Blogger.