Page 264 - CA_Blue( J )_Class10
P. 264
.
access-specifier static datatype variable3;
access-specifier static datatype variable4;
.
.
access-specifier return-type method-name1(parameter list with data-type)
{
Body of the method1;
}
access-specifier return-type method-name2(parameter list with data-type)
{
Body of the method2;
}
.
.
}
Now, let us take an example of a class in Java.
class Computer
{
//members variables
name;
speed;
accuracy;
//member methods
processing()
{
}
storing()
{
}
}
To create a class rectangle where the data members are length and breadth, and methods are:
Program 1
void input () - Inputs value in length and breadth
void area_rec () - Calculates the area of the rectangle and displays it
void perimeter_rec () - Calculates the perimeter of the rectangle and displays it.
1 import java.util.*;
2 class rectangle
3 {
4 int length,breadth;
5
6 public void input ()
7 {
8 Scanner sc= new Scanner (System.in);
262262 Touchpad Computer Applications-X

