summaryrefslogtreecommitdiff
path: root/oop/02-inheritance-01
diff options
context:
space:
mode:
Diffstat (limited to 'oop/02-inheritance-01')
-rw-r--r--oop/02-inheritance-01/.gitignore1
-rw-r--r--oop/02-inheritance-01/App.java12
-rw-r--r--oop/02-inheritance-01/Person.java23
-rw-r--r--oop/02-inheritance-01/Student.java22
4 files changed, 58 insertions, 0 deletions
diff --git a/oop/02-inheritance-01/.gitignore b/oop/02-inheritance-01/.gitignore
new file mode 100644
index 0000000..6b468b6
--- /dev/null
+++ b/oop/02-inheritance-01/.gitignore
@@ -0,0 +1 @@
+*.class
diff --git a/oop/02-inheritance-01/App.java b/oop/02-inheritance-01/App.java
new file mode 100644
index 0000000..5ab7c3c
--- /dev/null
+++ b/oop/02-inheritance-01/App.java
@@ -0,0 +1,12 @@
+public class App {
+ public static void main(String[] args) {
+ Person p1 = new Person("Kamal");
+ System.out.println(p1.toString());
+
+ Student s1 = new Student("Tharindu", "ST003");
+ System.out.println(s1.toString());
+
+ Person p2 = new Student("Yasas", "ST002");
+ System.out.println(p2.toString());
+ }
+} \ No newline at end of file
diff --git a/oop/02-inheritance-01/Person.java b/oop/02-inheritance-01/Person.java
new file mode 100644
index 0000000..9b921b7
--- /dev/null
+++ b/oop/02-inheritance-01/Person.java
@@ -0,0 +1,23 @@
+public class Person {
+
+ String name;
+
+ public Person(String name) {
+ this.name = name;
+ }
+
+ public String getName() {
+ return name;
+ }
+
+
+ public void setName(String name) {
+ this.name = name;
+ }
+
+
+ @Override
+ public String toString() {
+ return "Person [name=" + name + "]";
+ }
+}
diff --git a/oop/02-inheritance-01/Student.java b/oop/02-inheritance-01/Student.java
new file mode 100644
index 0000000..45ac18e
--- /dev/null
+++ b/oop/02-inheritance-01/Student.java
@@ -0,0 +1,22 @@
+public class Student extends Person {
+ String studentID;
+
+ public Student(String name, String studentID) {
+ super(name);
+ this.studentID = studentID;
+ }
+
+ public String getStudentID() {
+ return studentID;
+ }
+
+ public void setStudentID(String studentID) {
+ this.studentID = studentID;
+ }
+
+ @Override
+ public String toString() {
+ return "Student [name=" + name + ", studentID=" + studentID + "]";
+ }
+
+}