Loading
View RSS Feed

Goldsonam's Blog

Single Inheritance Example In Java

Rating: 14 votes, 2.86 average.
Write a program to maintain the ofice database using single inheritance. Superclass is Employee that contain the information as follows- Emp_code, Emp_name, Address, Ph_no, Da-10%, Hra-20%. Create three subclass of Manager, Typist, officer each class having their own basic pay & da,hra remain same.
Code:
import java.io.*;

class employee
{
 int empcode;
 String empname,empadd;
 int phno;
 final static int da=10;
 final static int hra=20;
int salary;
int basic;
employee()
{
 empcode=phno=0;
 empname=empadd="null";
}
employee(int c,int p,String n,String a)
{
 empcode=c;
empname=n;
phno=p;
empadd=a;

}
 
void salary_comp()
{
 salary=basic+(basic*da/100)+(basic*hra/100);
System.out.println("NET SALARY"+salary);
}
}

class manager extends employee
{
 
 manager(int c,int p,String n,String a,int b)
{
 super(c,p,n,a);
basic=b;
}
manager()
{
super();
basic=0;
}
}


class typist  extends employee
{
 
 typist(int c,int p,String n,String a,int b)
{
 super(c,p,n,a);
basic=b;
}
typist()
{
super();
basic=0;
}
}

class emp
{
public static void main(String args[])
{
 manager m=new manager(1,9904567,"keshav","kol",15000);
 typist t=new typist(30,687900,"ram","mum",20000);
 System.out.println("MANAGER:");
 m.salary_comp();
System.out.println("TYPER:");
t.salary_comp();
}
}

Submit "Single Inheritance Example In Java" to Digg Submit "Single Inheritance Example In Java" to del.icio.us Submit "Single Inheritance Example In Java" to StumbleUpon Submit "Single Inheritance Example In Java" to Google

Updated 02-14-2011 at 07:39 PM by Harsh

Categories
Java

Comments

  1. angad's Avatar



Disclaimer: Users of techforum4u.com are responsible for ensuring that any material they post (article, blog posts, images or other mulitimedia content) does not violate or infringe upon the copyright, patent, trademark, or any personal or proprietary rights of any third party, and is posted with the permission of the owner of such rights.Anyone who violates these rules may have their access privileges removed without warning.