I understand that the fight method returns a boolean and takes an object of the Cat class as it's parameter stored in the variable anotherCat. However, what does the this.weight, this.strength refer to?
Secondly, why am I unable to call the method in my main? It says it can't be accessed from a static context?
Thanks.
package com.codegym.task.task05.task0502;
/*
Implement the fight method
*/
public class Cat {
public int age;
public int weight;
public int strength;
public Cat() {
}
public boolean fight(Cat anotherCat) {
//write your code here
if(this.weight<anotherCat.weight && this.age<anotherCat.age && this.strength>anotherCat.strength)
return true;
else
return false;
}
public static void main(String[] args) {
Cat cat1 = new Cat();
cat1.age = 3;
cat1.weight = 15;
cat1.strength = 20;
Cat cat2 = new Cat();
cat2.age = 2;
cat2.weight = 10;
cat2.strength = 15;
}
}