Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // this Class is for java homework name: Lesson012_28_08_19_Task1
- public class Cat {
- private String name, color;
- private int whiskersLenght;
- static private int i=1; // object creation count
- // builders:
- public Cat(String name, int whLen, String color) {
- this.name = name;
- this.whiskersLenght = whLen;
- this.color = color;
- }
- public Cat() {
- this("Cat No"+i, (int)(Math.random()*4), "black");
- i += 1;
- }
- // = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = =
- @Override
- public String toString() {
- return "Cat{" +
- "name='" + name + '\'' +
- ", color='" + color + '\'' +
- ", whiskersLenght=" + whiskersLenght +
- '}';
- }
- }
- // ####################################################################################################
- // this Class is for java homework name: Lesson012_28_08_19_Task1
- public class Cat {
- private String name, color;
- private int whiskersLenght;
- static private int i=1; // object creation count
- // builders:
- public Cat(String name, int whLen, String color) {
- this.name = name;
- this.whiskersLenght = whLen;
- this.color = color;
- }
- public Cat() {
- this("Cat No"+i, (int)(Math.random()*4), "black");
- i += 1;
- }
- // = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = =
- @Override
- public String toString() {
- return "Cat{" +
- "name='" + name + '\'' +
- ", color='" + color + '\'' +
- ", whiskersLenght=" + whiskersLenght +
- '}';
- }
- }
- // ####################################################################################################
- // this Class is for java homework name: Lesson012_28_08_19_Task1
- public class SiamiCat extends Cat {
- private String favoriteFood;
- // builders:
- public SiamiCat(String name, int whLen, String color, String food) {
- super(name, whLen, color);
- this.favoriteFood = food;
- }
- public SiamiCat() {
- super();
- this.favoriteFood = "Tuna";
- }
- public SiamiCat(String food) {
- super();
- this.favoriteFood = food;
- }
- // = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = =
- @Override
- public String toString() {
- return super.toString() + " SiamiCat{" +
- "favoriteFood=" + favoriteFood +
- '}';
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement