\ Classes
provide a convenient method for packing together a group of logically related
data items and functions that work on them.
In
Java, the data items are called fields and functions are called methods.
A
class is declared by using class
keyword:
class
classname {
type instance-variable1;
type instance-variable2;
//….
type instance-variableN;
type methodname1(parameter-list) {
//body
of the method.
}
type methodname2(parameter-list) {
//body
of the method.
}
//….
type methodnameN(parameter-list) {
//body
of the method.
}
}
Ex:
class
Myclass {
int
a;
int b;
void Getdata(int x,int y) {
a=x;
b=y;
}
void Display() {
System.out.println(“A=
“ +a+ “ B= “+b);
}
}
No comments:
Write comments