Skip to content

Commit 4b92461

Browse files
Banti ShawBanti Shaw
authored andcommitted
Class other properties
1 parent ac80b5a commit 4b92461

9 files changed

+54
-0
lines changed

Ex14ClassInheritance.class

146 Bytes
Binary file not shown.

Ex14ClassInheritance.java

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,45 @@
11
package JavaEntry;
22

3+
// Inheritance : use to inherit attributes and methods from another class.
4+
// Polymorphism: uses the smae methods to perform different tasks.
5+
6+
37
class Student {
48
String name = "Banti";
59
String universityName = "SMU";
610
void getFullName(){
711
System.out.println(name + " Shaw");
812
}
13+
public void whichClass(){
14+
System.out.println("I am in Class 10");
15+
}
16+
}
17+
18+
class HigherEdu extends Student {
19+
public void whichClass(){
20+
System.out.println("I am in Class 12");
21+
}
922
}
1023

24+
class GraduateDegree extends Student {
25+
public void whichClass(){
26+
System.out.println("I am in College for Bachelor's Degree");
27+
}
28+
}
29+
30+
31+
1132
class Ex14ClassInheritance extends Student { // Inherit the abstract class with the extends keyword
1233
public static void main(String[] args){
1334
Student studentObj = new Student();
1435
studentObj.getFullName();
1536
System.out.println(studentObj.universityName);
37+
studentObj.whichClass();
38+
39+
HigherEdu higherEduObj = new HigherEdu();
40+
higherEduObj.whichClass();
41+
42+
GraduateDegree graduateDegreeObj = new GraduateDegree();
43+
graduateDegreeObj.whichClass();
1644
}
1745
}

Ex15ClassInner.class

731 Bytes
Binary file not shown.

Ex15ClassInner.java

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
package JavaEntry;
2+
3+
class ParentClass {
4+
int x = 10;
5+
String name = "Banti";
6+
7+
class InnerClass {
8+
int y = 20;
9+
public String getName(){
10+
return name;
11+
}
12+
}
13+
}
14+
15+
16+
public class Ex15ClassInner {
17+
public static void main(String[] args){
18+
ParentClass parenClassObj = new ParentClass();
19+
ParentClass.InnerClass innerClassObj = parenClassObj.new InnerClass();
20+
21+
System.out.println(parenClassObj.x);
22+
System.out.println(innerClassObj.y);
23+
System.out.println(innerClassObj.getName());
24+
25+
}
26+
}

GraduateDegree.class

457 Bytes
Binary file not shown.

HigherEdu.class

431 Bytes
Binary file not shown.

ParentClass$InnerClass.class

433 Bytes
Binary file not shown.

ParentClass.class

351 Bytes
Binary file not shown.

Student.class

1.05 KB
Binary file not shown.

0 commit comments

Comments
 (0)