IDNLearn.com: Your one-stop destination for finding reliable answers. Ask your questions and receive reliable and comprehensive answers from our dedicated community of professionals.

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 :

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.