Wednesday, 7 February 2018

Program to understand creation of classes,object and method

class Room
{
float length;
float breadth;
void getdata(float a,float b)
{
length=a;
breadth=b;

}

}

class RoomArea
{
public static void main(String args[])
{
float area;
Room R1=new Room();//creating object of class Room
R1.getdata(14,10);//calling method of Room class
area=R1. length*R1.breadth;//calling variables of Room class
System.out.println("Area of Room is:"+area);
}
}

No comments:

Post a Comment