Skip to content

Commit 75d09a3

Browse files
Add Exercise 11
1 parent ba9e0df commit 75d09a3

File tree

3 files changed

+42
-0
lines changed

3 files changed

+42
-0
lines changed
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
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+
}
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
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
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
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

0 commit comments

Comments
 (0)