OCJP

What is class?

In general term ‘Class is a collection of Data + Data Related Functions‘. Class is a collection of Objects. Class contains the properties and method. In other word Class contains the properties that defines the class.

Like

If we want to create a class of  Vehicle then decide the properties those define vehicle and their attributes like..

Type of Vehicle,Color,Capacity,Weight and so more. These are the attributes of the class

Drive(), Move(), Stop(),Buy(),Sell() and so more are the process that we perform over the vehicle, those are methods.

Now you can define the class like below

class Vehicle
{
private String vehicletype;
private String color;
privte int capacity;
private double weight;


public void move()
{
//Some Code Here
}

public void stop()
{
//Code Here
}

}

Note :Class Name Should be in TitleCase. Functions in class should be named with camelCase. Visibility of Class Members are described in our other article.

Leave a Reply

Your email address will not be published. Required fields are marked *


× How can I help you?