IDL Constructed Types   «Prev  Next»

IDL-to-Java Mapping for enums - Quiz

Each question is worth one point. Select the best answer or answers for each question.
 
1. How will the UserType enum in the following IDL map to Java ?
module Module4
{
 enum UserType {admin, user, guest};
};

Please select the best answer.
  A.
package Module4;
public final class UserType
 implements org.omg.CORBA.portable.IDLEntity
{
 private int value = -1;
 public static final int _admin = 0;
 public static final UserType admin = new UserType(_admin);
 public static final int _user = 1;
 public static final UserType user = new UserType(_user);
 public static final int _guest = 2;
 public static final UserType guest = new UserType(_guest);
 public int value()
 {
  return value;
 }
 public static UserType from_int(int value)
 {
  switch (value) {
   case _admin: return admin;
   case _user: return user;
   case _guest: return guest;
   default: return null;
  }
 }
 public UserType(int i)
 {
  value = i;
 }

}

  B.
package Module4;
public final class UserType
 implements org.omg.CORBA.portable.IDLEntity
{
 private int value = -1;
 public static final int _admin = 0;
 public final UserType admin = new UserType(_admin);
 public static final int _user = 1;
 public final UserType user = new UserType(_user);
 public static final int _guest = 2;
 public final UserType guest = new UserType(_guest);
 public int value()
 {
  return value;
 }
 public UserType from_int(int value)
 {
  switch (value) {
   case _admin: return admin;
   case _user: return user;
   case _guest: return guest;
   default: return null;
  }
 }
 private UserType(int i)
 {
  value = i;
 }
}
  C.
package Module4;
public final class UserType
 implements org.omg.CORBA.portable.IDLEntity
{
 private int value = -1;
 public static final int _admin = 0;
 public static final UserType admin = new UserType(_admin);
 public static final int _user = 1;
 public static final UserType user = new UserType(_user);
 public static final int _guest = 2;
 public static final UserType guest = new UserType(_guest);
 public int value()
 {
  return value;
 }
 public static UserType from_int(int value)
 {
  switch (value) {
   case _admin: return admin;
   case _user: return user;
   case _guest: return guest;
   default: return null;
  }
 }
 private UserType(int i)
 {
  value = i;
 }
}


2. Which is a correct code fragment to return a guest UserType object given the following IDL ?
module Module4
{
enum UserType {admin, user, guest};
};
Please select the best answer.
  A. return new UserType(UserType._guest);
  B. return UserType.guest;
  C. return UserType.guest.value()

3. Will the java.lang.Object equals() and hash() methods work correctly for enum objects in Java ?
Please select the best answer.
  A. equals() does not work correctly, hash() does not work correctly.
  B. equals() does not work correctly, hash() does work correctly.
  C. equals() does work correctly, hash() does not work correctly.
  D. equals() does work correctly, hash() does work correctly.

Correct answers:

Your Score: 0