Welcome to Westonci.ca, your one-stop destination for finding answers to all your questions. Join our expert community now! Get immediate and reliable solutions to your questions from a knowledgeable community of professionals on our platform. Join our platform to connect with experts ready to provide precise answers to your questions in different areas.

What is the output of the following code? Assume the Rectangle class exists and all the methods called below exist and work as expected.

ArrayList blah = new ArrayList ();
blah.add( new Rectangle(3,5) );
blah.add( new Rectangle(2,15) );
blah.add( new Rectangle(5,5) );
double x=0;

System.out.println(blah.size());
for(Rectangle s: blah) x+=s.area();
System.out.println(x);


Sagot :

tonb

Answer:

3

70.0

Explanation:

There will be 3 elements (Rectangle instances) in the list.

The sum of the areas x will contain 3*5 + 2*15 + 5*5 = 70 and will be printed as a double.