OOPortal OOPortal


IDL Constructed Types   «Prev  Next»

IDL-to-Java mapping for unions - Quiz

Each question is worth one point. Select the best answer or answers for each question.
 
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;
 }

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.

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;


Score =
Correct answers: