IDL-to-Java mapping for unions - Quiz Explanation

The answers you selected are indicated below, along with text that explains the correct answers.
 
1. Given the following IDL, which of these answers contains an accessor method that would be found in the corresponding generated Java class?
module Module4
{
enum SizeType {smaller, bigger, questionable};
 union SizedNumber switch (SizeType)
 {
 case smaller: short smallNum;
 case bigger: long bigNum;
 default: long someNum;
 };
};

Please select the best answer.
  A.
 public short smallNum()
 {
  if( discriminator != Module4.SizeType.bigger)
   throw new org.omg.CORBA.BAD_OPERATION();
  return smallNum;
 }
  B.
 public int someNum()
 {
  return someNum;
 }
  C.
 public int bigNum()
 {
  if( discriminator != Module4.SizeType.bigger)
   throw new org.omg.CORBA.BAD_OPERATION();
  return bigNum;
 }
  The correct answer is C. The correct answer is C, because it adheres to the mapping, the discriminator is checked and the appropriate value is returned. A is incorrect because the discriminator checked is wrong; it should be againstsmaller, notbigger. B is incorrect because there is no check against the discriminator.

2. What reason peculiar to the nature of unions makes it important that the fields in the corresponding Java class not be public? Consider the fact that the fields for struct classes are public.
Please select the best answer.
  A. If the fields were public, it would be possible to bypass the CORBA security model.
  B. If the fields were public, it would be possible to get or set a value other than the one indicated by the union's discriminator.
  C. If the field were public, it would be possible to get or set a value of a type other than that indicated by the union.
  The correct answer is B. Unions are meant to hold one value at a time as indicated by the discriminator. Direct field access would bypass the discriminator, allowing for possibly erroneous getting or setting. A is incorrect because the issue has nothing to do with CORBA security. C is incorrect because even if the fields were public, they would still be typed properly; the problem is not one of typing.

3. Given the following IDL, which of the following answers is a correct return of a bigger SizedNumber?

module Module4
{
enum SizeType {smaller, bigger, questionable};
 union SizedNumber switch (SizeType)
 {
 case smaller: short smallNum;
 case bigger: long bigNum;
 default: long someNum;
 };
};

Please select the best answer.
  A.
SizedNumber num = new SizedNumber();
num.bigNum(999);
return num;
  B.
return new SizedNumber(999);
  C.
SizedNumber num = new SizedNumber(Module4.SizeType.bigger);
num.bigNum(999);
return num;
  The correct answer is A. The correct answer is A, because the provided no-args constructor and appropriate mutator are used. B and C are incorrect because the only constructor generated is the no-args constructor; there are no others.