Java Language Interview Question and Answers

21. What are wrapper classes?
  primitive data types may be converted into object types by using the wrapper classes contained in the java.lang package.
Exampes : int, float, long, char, double
22. What is the difference between an instance variable and a static variable?
  Class variables are called static variables. There is only one occurrence of a class variable per JVM per class loader.When a class is loaded the class variables are initialized.
Instance variables are non-static and there is one occurrence of an instance variable in each class instance.Also known as a member variable or a field.
23 Where and how can you use a private constructor?
  Private constructor is used if you do not want other classes to instantiate the object and to prevent subclassing.The instantiation is done by a public static method (i.e. a static factory method) within the same class.
24. What is type casting?
  Type casting means treating a variable of one type as though it is another type.
Examples :
int m = 5;
byte n =i;
25. What is a user defined exception?
  User defined exceptions may be implemented by defining a new exception class by extending the Exception class.
123456789101112 Page 5 of 12