Give an example of a class and an example of an object. Describe what a class is, what an object is, and how they are related. Use your examples to illustrate the descriptions
Example of the class:
class Shirt{
private int size;
public Shirt (int size){
this.size = size;
}
}
Example of creating the object:
Shirt medium = new Shirt(10);
A class is a description of an entity.
An object is an instance of a class.
In order to use the functionality of a class(in general), you must create an object of this class.
In the example above, the object is created using the keyword "new".
Comments
Leave a comment