File tree Expand file tree Collapse file tree 3 files changed +42
-0
lines changed
Lab Sheets/Lab Sheet 03/Lakshan/Exercise 11 Expand file tree Collapse file tree 3 files changed +42
-0
lines changed Original file line number Diff line number Diff line change 1+ public class Dog extends Pet {
2+ int noOfMasters ;
3+ public Dog (String n , String o , int a , int m ) {
4+ super (n , o , a );
5+ this .noOfMasters = m ;
6+ }
7+ public Dog (String n , String o ) {
8+ super (n , o );
9+ this .noOfMasters = 1 ;
10+ }
11+ public void showDetails (){
12+ super .showDetails ();
13+ System .out .println ("I am a dog. I have " +this .noOfMasters +" masters at home" );
14+ }
15+ }
Original file line number Diff line number Diff line change 1+ public class Main {
2+ public static void main (String [] args ){
3+ Cat cat1 = new Cat ("Kitty" , "James" );
4+ cat1 .showDetails ();
5+ Dog dog1 = new Dog ("Jimi" , "Jhon" );
6+ dog1 .showDetails ();
7+ }
8+ }//end of the demo class
Original file line number Diff line number Diff line change 1+ public class Pet {
2+ private String name ;
3+ private String owner ;
4+ private int age ;
5+
6+ public Pet (String n , String o , int a ) {
7+ this .name = n ;
8+ this .owner = o ;
9+ this .age = a ;
10+ }
11+ public Pet (String n , String o ) {
12+ this .name = n ;
13+ this .owner = o ;
14+ this .age = 0 ;
15+ }
16+ public void showDetails (){
17+ System .out .println ("I am a pet. My name is " +this .name +". My owner is " +this .owner );
18+ }
19+ }//end of the pet class
You can’t perform that action at this time.
0 commit comments