Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package com.javarush.test.level05.lesson09.task02;
- /* Создать класс Cat
- Создать класс Cat (кот) с пятью конструкторами:
- - Имя, возраст (вес стандартный)
- - вес, цвет, адрес ( чужой домашний кот)
- Задача инициализатора – сделать объект валидным.
- Например, если вес не известен, то нужно указать какой-нибудь средний вес. Кот не может ничего не весить.
- То же касательно возраста. А вот имени может и не быть (null). То же касается адреса: null.
- */
- public class Cat
- {
- String name = null;
- int weight = 4;
- int age = 10;
- String color1=null;
- String address1 = null;
- public Cat (String name) {//- Имя
- this.name=name;
- }
- public Cat (String name,int weight,int age) {//- Имя, вес, возраст
- this.name=name;
- this.weight=weight;
- this.age=age;
- }
- public Cat (String name, int age) {//- Имя, возраст (вес стандартный)
- this.name=name;
- this.age=age;
- int weight=this.weight;
- }
- public Cat (int weight, String color1) {//- вес, цвет, (имя, адрес и возраст – неизвестные. Кот - бездомный)
- this.weight = weight;
- this.color1 = color1;
- String name=this.name;
- String address1=this.address1;
- int age=this.age;
- }
- public Cat (int weight,String color1, String address1) {
- this.weight = weight;
- this.color1=color1;
- this.address1=address1;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment