- Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathEx14ClassInheritance.java
More file actions
Latest commit
45 lines (35 loc) · 1.16 KB
/
Copy pathEx14ClassInheritance.java
File metadata and controls
45 lines (35 loc) · 1.16 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
packageJavaEntry;
// Inheritance : use to inherit attributes and methods from another class.
// Polymorphism: uses the smae methods to perform different tasks.
classStudent {
Stringname = "Banti";
StringuniversityName = "SMU";
voidgetFullName(){
System.out.println(name + " Shaw");
}
publicvoidwhichClass(){
System.out.println("I am in Class 10");
}
}
classHigherEduextendsStudent {
publicvoidwhichClass(){
System.out.println("I am in Class 12");
}
}
classGraduateDegreeextendsStudent {
publicvoidwhichClass(){
System.out.println("I am in College for Bachelor's Degree");
}
}
classEx14ClassInheritanceextendsStudent { // Inherit the abstract class with the extends keyword
publicstaticvoidmain(String[] args){
StudentstudentObj = newStudent();
studentObj.getFullName();
System.out.println(studentObj.universityName);
studentObj.whichClass();
HigherEduhigherEduObj = newHigherEdu();
higherEduObj.whichClass();
GraduateDegreegraduateDegreeObj = newGraduateDegree();
graduateDegreeObj.whichClass();
}
}