Simple Program on Class in Java

In this class, We discuss Simple Programs on Class in Java.

The reader should have prior knowledge of the class and object. Click Here.

This a simple example to understand the concepts we discussed in previous classes.

The reader should take the question and write the code for best practice.

Question:

Write a Java program to find the area and perimeter of a rectangle.

The below diagram shows the code.

The area of a rectangle is length * width.

The perimeter of a rectangle is 2*(length + width)

Both the above need length and width.

We consider length and width as instance variables.

The area is one logic, so consider it as a method.

Similarly, consider the perimeter method.