Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.sql.SQLOutput;
- public class Cat {
- private String name;
- private String color;
- private int years;
- //default constructor
- public Cat(){
- this.name = "Tom";
- this.color = "gray";
- this.years = 2;
- }
- //Constructor with parametres
- public Cat(String nameLion, String colorLion, int yearsLion){
- this.name = nameLion;
- this.color = colorLion;
- this.years = yearsLion;
- }
- static void foodCat( ){
- System.out.println("The cat eats five times a day.");
- }
- static void sleepCat( ){
- System.out.println("The cat sleeps 12-16 hours a day.");
- }
- static void foodLion( ){
- System.out.println("The lion eats around 6kg every day.");
- }
- static void sleepLion( ){
- System.out.println("The lion spends between 16 and 20 hours each day resting and sleeping.");
- }
- public static void main(String[] args) {
- Cat cat1 = new Cat();
- foodCat();
- sleepCat();
- System.out.println("Cat's name is: " + cat1.name + "\n" + "Cat's color is: " + cat1.color + "\n" + "Cat's years are: " + cat1.years);
- System.out.println();
- Cat lion = new Cat("Jack", "orange", 5 );
- foodLion();
- sleepLion();
- System.out.println("Lion's name is: " + lion.name + "\n" + "Lion's color is: " + lion.color + "\n" + "Lion's years are: " + lion.years);
- }
- }
Add Comment
Please, Sign In to add comment