Student Details - Hierarchical Inheritance

5 comments - Post a comment

--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 */

 
This Post has 5 Comments Add your own!
Anonymous - December 30, 2009 at 3:55 AM

What quite good topic

Anonymous - January 24, 2010 at 10:37 PM

Ah, the land of the free!
You have the right to free speech as long as you speak English.
---
best regards, Greg

Anonymous - September 6, 2010 at 8:25 PM

oh your source codes are really helpful. can anybody help me writing a java program which prints a pyramid of the form
*******
******
*****
****
***
**
*

Anonymous - September 6, 2010 at 8:25 PM

oh your source codes are really helpful. can anybody help me writing a java program which prints a pyramid of the form
*******
******
*****
****
***
**
*

Anonymous - September 10, 2012 at 3:07 PM

It's really a nice blog. I've learn Java through different websites and college but was kind of put off and unable to grasp the core. Could do simple programs but no inheritance. But 2day have been practicing reading through your codes. Thanks fella.... for making my life easy and flaring my passion to do programming in java. Thumbs up for you!

Post a Comment