I don't know if this is a wrong way to ask questions, as it's really a continuation of what I got a tip of in another question.
The thing is, I was wondering what static keywords did, and I think I understood it. My question now is, did I understand correctly? And how do I create instances of "Dogs"?
class Dog {
static String form /* of all dogs */ = "Doggy-like";
static int quantity /* of dogs */ = 5;
String colour; /* of a specific dog */
String size; /* of a specific dog */
}
class Cat {
static String form /* of all cats */ = "Catty-like";
static int quantity/* of cats */ = 3;
String colour; /* of a specific cat */
String size; /* of a specific cat */
}
public class Animals {
public static void main(String[] args){
System.out.println("There are "+Cat.quantity+" cats.");
System.out.println("There are "+Dog.quantity+" dogs.");
/* EDIT: */
Dog Mike = new Dog();
Dog Pete = new Dog();
Cat Sushi = new Cat();
Cat Michael = new Cat();
Cat Pete = new Cat();
Dog.Mike.size="Big";
Dog.Mike.colour="Red";
Dog.Pete.size="Small";
Cat.Sushi.size="Small";
}
}
I'm also wondering if there is a conflict between those Pete cats and dogs, and if it's correct to define their sizes like that. Does it make a difference to create it inside public class Animals, or inside their respective classes (or another class, for that matter)?