Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package eleven;
- public class Cat {
- public String name, color;
- int safam;
- public Cat(String n, String c, int s) {// constructor for cat
- this.name = n;
- this.color = c;
- this.safam = s;
- }
- public String toString() {// output for cat
- return "Cat Name " + this.name + " Color " + this.color + " mustache length " + this.safam;
- }
- }
- ----------------------------------------------------------------------------------------------------------
- package eleven;
- public class StreetCat extends Cat {
- public int fightNum;
- public StreetCat(String n, String c, int s, int fn) {// constructor for street cat
- super(n, c, s);
- this.fightNum = fn;
- }
- public String toString() {// output for street cat
- return super.toString() + " Number of fights " + this.fightNum;
- }
- }
- ----------------------------------------------------------------------------------------------------------
- package eleven;
- public class SiamiCat extends Cat {
- public String foodType;
- public SiamiCat(String n, String c, int s, String ft) {// constructor for siami cat
- super(n, c, s);
- this.foodType = ft;
- }
- public String toString() {// output for siami cat
- return super.toString() + " favorite food " + this.foodType;
- }
- }
- ----------------------------------------------------------------------------------------------------------
- package eleven;
- public class MainCat {
- public static void main(String[] args) {
- Cat c1 = new Cat("Lodvik", "Redhead", 5);// creating cat
- StreetCat c2 = new StreetCat("Voljin", "Redhead", 4, 7);// creating a street cat
- SiamiCat c3 = new SiamiCat("Cloe", "White", 3, "Fish");// creating a siami cat
- System.out.println(c1);// showing output for cat
- System.out.println(c2);// showing output for street cat
- System.out.println(c3);// showing out for siami cat
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement