Question: What are wrapped classes
Wrapped classes are classes that allow primitive types to be accessed as objects.
Question: What are the four general cases for Conversion and Casting
Conversion of primitives
Casting of primitives
Conversion of object references
Casting of object references
Question: When can conversion happen
It can happen during
Question: What are the rules for primitive assignment and method call conversion
A boolean can not be converted to any other type
A non Boolean can be converted to another non boolean type, if the conversion is widening conversion
A non Boolean cannot be converted to another non boolean type, if the conversion is narrowing conversion
See figure below for simplicity
Question: What are the rules for primitive arithmetic promotion conversion
For Unary operators :
If operant is byte, short or a char it is converted to an int
If it is any other type it is not converted
For binary operands :
If one of the operands is double, the other operand is converted to double
Else If one of the operands is float, the other operand is converted to float
Else If one of the operands is long, the other operand is converted to long
Else both the operands are converted to int
Question: What are the rules for casting primitive types
You can cast any non Boolean type to any other non boolean type
You cannot cast a boolean to any other type; you cannot cast any other type to a boolean
Question: What are the rules for object reference assignment and method call conversion
An interface type can only be converted to an interface type or to object. If the new type is an interface, it must be a superinterface of the old type.
A class type can be converted to a class type or to an interface type. If converting to a class type the new type should be superclass of the old type. If converting to an interface type new type the old class must implement the interface.
An array maybe converted to class object, to the interface cloneable, or to an array. Only an array of object references types may be converted to an array, and the old element type must be convertible to the new element.
Question: What are the rules for Object reference casting
Casting from Old types to Newtypes
Compile time rules
Ask Questions? Discuss: Core Java Interview Question, Interview Question
Post your Comment
If you are facing any programming issue, such as compilation errors or not able to find the code you are looking for.
Ask your questions, our development team will try to give answers to your questions.