-
Notifications
You must be signed in to change notification settings - Fork 6.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1220 from pretam591/hybrid_inheritance
Implementation of Hybrid Inheritance
- Loading branch information
Showing
1 changed file
with
45 additions
and
0 deletions.
There are no files selected for viewing
45 changes: 45 additions & 0 deletions
45
Program's_Contributed_By_Contributors/Java_Programs/Misc/HierarchialInheritance.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
class Teacher | ||
{ | ||
int com; | ||
void taught(int a,int b) | ||
{ | ||
System.out.println("Age of the teacher = " + a); | ||
com = b; | ||
} | ||
void show() | ||
{ | ||
System.out.println("Syllabus Completed:- " + com + "%\n"); | ||
} | ||
} | ||
|
||
class Student1 extends Teacher | ||
{ | ||
void report1(int s, int m) | ||
{ | ||
show(); | ||
System.out.println("\n1st STUDENT\n"); | ||
System.out.println("Syllabus Completed:- " + com + "%"); | ||
System.out.println("Marks obtained:- " + m); | ||
} | ||
} | ||
class Student2 extends Teacher | ||
{ | ||
void report2(int s, int m) | ||
{ | ||
System.out.println("\n2nd STUDENT\n"); | ||
System.out.println("Syllabus Completed:- " + s + "%"); | ||
System.out.println("Marks obtained:- " + m); | ||
} | ||
} | ||
|
||
class HierarchialInheritance | ||
{ | ||
public static void main(String args[]) | ||
{ | ||
Student1 s1 = new Student1(); | ||
Student2 s2 = new Student2(); | ||
s1.taught(60,98); | ||
s1.report1(90,75); | ||
s2.report2(70,68); | ||
} | ||
} |