A class is a template of an entity. It can be thought of as a ‘blueprint’ to create various objects, that share some common properties. Generally, it is the main way Object Oriented Programming Languages support abstraction

A class contains:

  • Attributes: Any variable that belongs to (is defined in) a class is considered to be an attribute.
  • Methods: Any function that is defined in a class is considered to be a method

Defining Classes

Java

In Java, a class is defined as such:

[Visibility Modifer] class [ClassName] {
	/*
	Class definition here
	*/
}

For example:

public class Fruit {
	//Attributes
	String name;
	int weight;
	//Methods
	void Ripen(int age) {}
}

Here, name and weight are attributes, while Ripen() is a method.