Basic Datatypes
- Which class does all the Enums extend?
-
View Hint View Answer Discuss in Forum
NA
Correct Option: B
All enums implicitly extend java.lang.Enum. Since Java does not support multiple inheritance, an enum cannot extend anything else.
- Are enums are type-safe?
-
View Hint View Answer Discuss in Forum
NA
Correct Option: C
Enums are type-safe as they have own name-space.
- Which of the following is the advantage of BigDecimal over double?
-
View Hint View Answer Discuss in Forum
NA
Correct Option: A
BigDecimal has unnatural syntax, needs more memory and creates great amount of garbage. But it has high precision which is useful for some calculations like money.
- Which of the below data type doesn’t support overloaded methods for +,-,* and /?
-
View Hint View Answer Discuss in Forum
NA
Correct Option: A
int, float, double provide overloaded methods for +,-,* and /. BigDecimal does not provide these overloaded methods.
- What is the output of below code snippet?
double d = 0.02;
double e = 0.03;
double f = e - d;
System.out.println(c);
BigDecimal _d = new BigDecimal("0.02");
BigDecimal _e = new BigDecimal("0.03");
BigDecimal _f = b.subtract(_d);
System.out.println(_f);
-
View Hint View Answer Discuss in Forum
NA
Correct Option: D
BigDecimal provides more precision as compared to double. Double is faster in terms of performance as compared to BigDecimal.