File tree Expand file tree Collapse file tree 2 files changed +30
-0
lines changed
Lab Sheets/Lab Sheet 03/Lakshan/Exercise 5 Expand file tree Collapse file tree 2 files changed +30
-0
lines changed Original file line number Diff line number Diff line change 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+ }
Original file line number Diff line number Diff line change 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+ }
You can’t perform that action at this time.
0 commit comments