Multilevel Inheritance Using Database Creation Java Program - Computer Programming

Latest

C C++ Java Python Perl Programs Examples with Output -useful for Schools & College Students

Friday, September 1, 2017

Multilevel Inheritance Using Database Creation Java Program

Write a java program to illustrate the multilevel inheritance using database creation as an example

Program:

class Imps
{
public static void main(String args[])
{
casual s= new casual();
s.getD("Ankit","Typist");
s.getS('m');
s.prF();
}
}
class Staff
{  String na;
String c;
void getD(String n,String co)
{
na=n;
c=co;
}
void prD()
{
System.out.println("Staff Detail:\nName:"+na+"\nCode:"+c);
}
}
class typist extends Staff
{
char speedCode;
void getS(char s)
{
speedCode=s;
}
void disS()
{
prD();
System.out.println("Speed Code:"+speedCode);
}
}
class casual extends typist
{
void prF()
{
int daw=0;
switch(speedCode)
{
case 's':daw=100;
break;
case 'm':daw=300;
break;
case 'f':daw=500;
break;
default:
System.out.println("Invalid Code entered .");
}
disS();
System.out.println("Daily Wages:Rs"+daw);
}

}

      Sample input and output:
Staff Details:

Name:XYZ
Code:Typist
SpeedCode:m
Daily Wages:Rs 300

No comments:

Post a Comment