go to previous page   go to home page   go to next page highlighting

Answer:

Three objects are created.

There is just one reference variable, value.


multiply()

Multiplication works as expected:

public BigInteger multiply( BigInteger val )

multiply val by the BigInteger that contains the method. The result is returned in a new BigInteger

Here is a program:


import java.math.BigInteger;

class AddSubtract
{

  public static void main ( String[] args )
  {
    BigInteger a = new BigInteger( "9" );
    BigInteger b = new BigInteger( "12" );
    BigInteger c = new BigInteger( "-20" );
    
    BigInteger d =  a.add( BigInteger.ONE ).multiply( b ).add( c );

    System.out.println("Result: " + d );
  }
}



Result: 100

Arithmetic expressions with BigInteger are sometimes not as nice as with the usual operators. There are no precedence rules to help. Read the above expression from left to right, performing the operations as they are encountered.

Each arithmetic operation creates a new object. Evaluating the above expression creates three objects. A reference to the last object is copied into the reference variable d.


QUESTION 10:

Which of the following, done with primitive ints, corresponds to the above expression for d?


go to previous page   go to home page   go to next page