Skip to content

Commit 7148d5e

Browse files
Add Exercise 5
1 parent 1bbcbea commit 7148d5e

File tree

2 files changed

+30
-0
lines changed

2 files changed

+30
-0
lines changed
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
public class InheritanceDemo {
2+
public static void main(String[] args) {
3+
// Create an object of Person class
4+
Person p1 = new Person("Lakshan", "Galle");
5+
6+
// Call showDetail() method
7+
p1.showDetail();
8+
}
9+
10+
}
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
public class Person {
2+
private String name;
3+
private String address;
4+
5+
//default constructor
6+
public Person() {
7+
this.name = "";
8+
this.address = "";
9+
}
10+
//constructor with parameters
11+
public Person(String name, String address) {
12+
this.name = name;
13+
this.address = address;
14+
}
15+
//showDetails method
16+
public void showDetail() {
17+
System.out.println("Name: " + name);
18+
System.out.println("Address: " + address);
19+
}
20+
}

0 commit comments

Comments
 (0)