91.9k views
11 votes
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);

1 Answer

7 votes

Answer:

3

70.0

Step-by-step 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.

User Hernando Casas
by
3.6k points