Why it is important to create a Class in Java?
What is an Object?
There are three main characteristics of Objects,
- State: Represents the data of an object.
- Behavior: Represents the behavior of an object such as deposit, withdrawal, etc.
- Identity: It is used internally by the JVM to identify each object uniquely.
What is a Class?
Example of class:
public class Car {
String carColor;
String carBrand;
String fuelType;
}
Example of object:
Car objCar = new Car();
Attribute Declaration.
Attributes / Fields are used to declare the properties of a class. These attributes are called instance variables. They can be intrinsic types like int, boolean, etc, or user-defined types.
example: private double salary;
Method Declaration.
Methods describe the responsibility of the class. These methods are common for all objects. Hence they are known as instance methods. A method always has a name and a return type and it can accept parameters.
example:
public void calculateArea(int height) {
int result = height*height;
System.out.println(result);
}







Trends is an amazing magazine Blogger theme that is easy to customize and change to fit your needs.