Tech moves fast! Stay ahead of the curve with Techopedia!
Join nearly 200,000 subscribers who receive actionable tech insights from Techopedia.
A class, in the context of Java, are templates that are used to create objects, and to define object data types and methods. Core properties include the data types and methods that may be used by the object. All class objects should have the basic class properties. Classes are categories, and objects are items within each category.
The above example is a class tree, and the string is the class data type. A class declaration is made up of the following parts:
This may be explained with a hypothetical example of a tree and types of trees. Generally, a tree should have branches, stems and leaves. Thus, if Banyan is a tree, Banyan should have all of the characteristics of a tree, such as branches, stems and leaves. It is impossible to say that a pigeon is a tree, because the pigeon does not have branches, stems and leaves. Similarly, basic Java object properties are defined within that object’s corresponding class.