5. Class And Objects:
The class binds together
data and methods which work on data. Class defines a general category and an
object is an instance or an occurrence of a class. The class consists of the
data items as well as the code or the functions which manipulate these data
items.
class Sample
{
int a,b;
void setAll(int i,int j)
{
a=i;
b=j;
}
void showAll( )
{
System.out.println("a= " + a +
" b="+b);
}
}
class SampleDemo
{
public static void main(String args[ ])
{
Sample ob=new Sample( );
ob.setAll(5,6);
ob.showAll( );
}
}
Comments
Post a Comment