A class defines the shared aspects of objects created from it. Classes consist variables and methods which will be associated with a particular object or all objects of a class through their states and behaviours.
Each class relates to a single concept and it's variables and methods should reflect that. For example a class that models a dog should probably not have variables like clothing or methods like meow.
For an object to be created from a class it's constructor needs to be called.
public class Dog {
int age;
public Dog(int age) {
this.age = age;
}
public void bark() {
System.out.println("Bark");
}
public int getAgeInDogYears() {
return this.age * 7;
}
}
In this example the class has 3 methods,
bark,getAgeInDogYearsand it's constructorDog. Additionally it has a variablesage.