
Hi I have written the following code:
class FirstRectangle{ public int rectArea(int l,int b){ int farea = l*b; System.out.println("Required Area::"+farea); return farea; }//method }//class
class SecondRectangle{ public int area(int l, int b){ int sarea = l*b; System.out.println("Required Area::"+sarea); return sarea; }//method }//class
public class MyShape{ public void combinedArea(FirstRectangle r,SecondRectangle sr){ r.rectArea(10,5); sr.area(15,10); }//method public static void main(String []s){ FirstRectangle r = new FirstRectangle(); SecondRectangle sr = new SecondRectangle(); MyShape m = new MyShape(); m.combinedArea(r,sr); }//main }//class
I want to add the area both rectangles and display them, but not getting how to do that. Please help me.

Hi Friend,
Here is your required code:
class FirstRectangle{
public int rectArea(int l,int b){
int farea = l*b;
System.out.println("Required Area::"+farea);
return farea;
}
}
class SecondRectangle{
public int area(int l, int b){
int sarea = l*b;
System.out.println("Required Area::"+sarea);
return sarea;
}
}
public class MyShape{
public void combinedArea(FirstRectangle r,SecondRectangle sr){
int area1=r.rectArea(10,5);
int area2=sr.area(15,10);
int sum=area1+area2;
System.out.println("Combined Area is: "+sum);
}
public static void main(String []s){
FirstRectangle r = new FirstRectangle();
SecondRectangle sr = new SecondRectangle();
MyShape m = new MyShape();
m.combinedArea(r,sr);
}
}
Thanks

Thanks for the solution. Now its working.
One more thing I need to ask: Is there any provision by which I can directly use farea and sarea for calculating the sum. I mean say the respective calculated values are stored in farea and sarea. Can't I use them directly?
If you are facing any programming issue, such as compilation errors or not able to find the code you are looking for.
Ask your questions, our development team will try to give answers to your questions.