Basic Java Interview Question and Answers

33. How to create an immutable class?
 
  • To create an immutable class following steps should be followed.
  • Create a final class.
  • Set the values of properties using constructor only.
  • Make the properties of the class final and private.
  • Do not provide any setters for these properties.
 
Your Name Your Email-ID
Your Answer
34. What is the difference between implicit and explicit type casting?
  An explicit conversion is where you use syntax to tell the program to do a conversion whereas in case of implicit type casting you need not provide the data type.
 
Your Name Your Email-ID
Your Answer
35. What is downcasting?
  Downcasting means creating from a general to a more specific type.
 
Your Name Your Email-ID
Your Answer
36. What are the different types of casting?
 
    There are two types of casting
  • Casting between primitive numeric types
  • Casting between object references
  • Casting between numeric types is used to convert larger values into smaller values. For e.g. double values to byte values.
  • Casting between object references helps you refer to an object by a compatible class, interface, or array type reference.
 
Your Name Your Email-ID
Your Answer