diff options
| author | Kamal Wickramanayake <kamal@inbox.lk> | 2026-02-22 20:20:13 +0530 |
|---|---|---|
| committer | Kamal Wickramanayake <kamal@inbox.lk> | 2026-02-22 20:20:13 +0530 |
| commit | 6fa0a63b3a594afb02f2bd52b4ea883a75cac0d0 (patch) | |
| tree | cd58235b46cd5b5d8e04f5ab35a17e47ecf7356e | |
| parent | baaba4a281b7d54e6b5d7767989c303b854b6932 (diff) | |
oop/inheritance sample code updated
| -rw-r--r-- | oop/02-inheritance-01/.gitignore (renamed from oop/02-inheritance/.gitignore) | 0 | ||||
| -rw-r--r-- | oop/02-inheritance-01/App.java | 12 | ||||
| -rw-r--r-- | oop/02-inheritance-01/Person.java | 23 | ||||
| -rw-r--r-- | oop/02-inheritance-01/Student.java | 22 | ||||
| -rw-r--r-- | oop/02-inheritance-02-abstract-classes/.gitignore | 1 | ||||
| -rw-r--r-- | oop/02-inheritance-02-abstract-classes/Account.java (renamed from oop/02-inheritance/Account.java) | 0 | ||||
| -rw-r--r-- | oop/02-inheritance-02-abstract-classes/AccountTest.java (renamed from oop/02-inheritance/AccountTest.java) | 0 | ||||
| -rw-r--r-- | oop/02-inheritance-02-abstract-classes/CheckingAccount.java (renamed from oop/02-inheritance/CheckingAccount.java) | 0 | ||||
| -rw-r--r-- | oop/02-inheritance-02-abstract-classes/SavingsAccount.java (renamed from oop/02-inheritance/SavingsAccount.java) | 0 |
9 files changed, 58 insertions, 0 deletions
diff --git a/oop/02-inheritance/.gitignore b/oop/02-inheritance-01/.gitignore index 6b468b6..6b468b6 100644 --- a/oop/02-inheritance/.gitignore +++ b/oop/02-inheritance-01/.gitignore 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 + "]"; + } + +} diff --git a/oop/02-inheritance-02-abstract-classes/.gitignore b/oop/02-inheritance-02-abstract-classes/.gitignore new file mode 100644 index 0000000..6b468b6 --- /dev/null +++ b/oop/02-inheritance-02-abstract-classes/.gitignore @@ -0,0 +1 @@ +*.class diff --git a/oop/02-inheritance/Account.java b/oop/02-inheritance-02-abstract-classes/Account.java index 91acb95..91acb95 100644 --- a/oop/02-inheritance/Account.java +++ b/oop/02-inheritance-02-abstract-classes/Account.java diff --git a/oop/02-inheritance/AccountTest.java b/oop/02-inheritance-02-abstract-classes/AccountTest.java index cc5056b..cc5056b 100644 --- a/oop/02-inheritance/AccountTest.java +++ b/oop/02-inheritance-02-abstract-classes/AccountTest.java diff --git a/oop/02-inheritance/CheckingAccount.java b/oop/02-inheritance-02-abstract-classes/CheckingAccount.java index a7c19b8..a7c19b8 100644 --- a/oop/02-inheritance/CheckingAccount.java +++ b/oop/02-inheritance-02-abstract-classes/CheckingAccount.java diff --git a/oop/02-inheritance/SavingsAccount.java b/oop/02-inheritance-02-abstract-classes/SavingsAccount.java index 497fb3d..497fb3d 100644 --- a/oop/02-inheritance/SavingsAccount.java +++ b/oop/02-inheritance-02-abstract-classes/SavingsAccount.java |
