-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathEx14ClassInheritance.java
More file actions
45 lines (35 loc) · 1.16 KB
/
Ex14ClassInheritance.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
package JavaEntry;
// Inheritance : use to inherit attributes and methods from another class.
// Polymorphism: uses the smae methods to perform different tasks.
class Student {
String name = "Banti";
String universityName = "SMU";
void getFullName(){
System.out.println(name + " Shaw");
}
public void whichClass(){
System.out.println("I am in Class 10");
}
}
class HigherEdu extends Student {
public void whichClass(){
System.out.println("I am in Class 12");
}
}
class GraduateDegree extends Student {
public void whichClass(){
System.out.println("I am in College for Bachelor's Degree");
}
}
class Ex14ClassInheritance extends Student { // Inherit the abstract class with the extends keyword
public static void main(String[] args){
Student studentObj = new Student();
studentObj.getFullName();
System.out.println(studentObj.universityName);
studentObj.whichClass();
HigherEdu higherEduObj = new HigherEdu();
higherEduObj.whichClass();
GraduateDegree graduateDegreeObj = new GraduateDegree();
graduateDegreeObj.whichClass();
}
}