Sunday 23 September 2012

Student Details - Hierarchical Inheritance

--BY Joel Mathias
/* Program to Implement Hierarchical Inheritance in java Programming Language */
class Info
{
int pid;
char branch;
char year;

Info(int p,char ch,char y)
{
pid = p;
branch = ch;
year = y;
}

void display()
{
System.out.println("\nPID\t: "+pid);

System.out.print("Branch\t: ");
if(branch == 'i')
System.out.println("Information Technology");
if(branch =='e')
System.out.println("Electronics and Telecommunication");
if(branch =='c')
System.out.println("Computer Science");

System.out.print("Year\t: ");
if(year == 'f')
System.out.println("FE");
if(year == 's')
System.out.println("SE");
if(year == 't')
System.out.println("TE");
}
}

class Fe extends Info
{
int c;
int cpp;

Fe(int p,char ch,char y,int m1,int m2)
{
super(p,ch,y);
c = m1;
cpp = m2;
}

void fdisplay()
{
display();
System.out.println("Performance:");
System.out.println("\tC\t"+c);
System.out.println("\tC++\t"+cpp);
}
}

class Se extends Info
{
int vb;
int html;

Se(int p,char ch,char y,int m1,int m2)
{
super(p,ch,y);
vb = m1;
html= m2;
}

void sdisplay()
{
display();
System.out.println("Performance:");
System.out.println("\tVB\t"+vb);
System.out.println("\tHTML\t"+html);
}
}

class Te extends Info
{
int matlab;
int java;

Te(int p,char ch,char y,int m1,int m2)
{
super(p,ch,y);
matlab = m1;
java = m2;
}
void tdisplay()
{
display();
System.out.println("Performance:");
System.out.println("\tMATLAB\t"+matlab);
System.out.println("\tSJava\t"+java);
}
}

class Language
{
public static void main(String args[])
{
Fe F = new Fe(1074,'i','f',9,8);
Se S = new Se(1064,'e','s',6,8);
Te T = new Te(1054,'c','t',9,9);
F.fdisplay();
S.sdisplay();
T.tdisplay();
}
}

/* Output *


PID : 1074
Branch : Information Technology
Year : FE
Performance:
C 9
C++ 8

PID : 1064
Branch : Electronics and Telecommunication
Year : SE
Performance:
VB 6
HTML 8

PID : 1054
Branch : Computer Science
Year : TE
Performance:
MATLAB 9
SJava 9 */

1 comment:

  1. perfect explanation about hierarchical inheritance java programming .its very useful.thanks for your valuable information.java training in chennai | java training in velachery

    ReplyDelete