Loading

Interview Questions of Data-Types

Q1. What is the difference between primitive and reference data types in Java?

Solution: 

  • Primitive Data Types: Store actual values. Examples include int, char, boolean, etc.
  • Reference Data Types: Store references (addresses) to objects. Examples include arrays, classes, interfaces.
Q2. Can you assign a double value to a float variable directly?

Solution: No, assigning a double value to a float variable directly will result in a compilation error due to potential loss of precision. You need to cast it explicitly.
double d = 10.5; float f = (float) d;

Q3. What is the range of the char data type in Java?

Solution: The char data type in Java is a 16-bit Unicode character. It has a range from \u0000 (0) to \uffff (65,535).

Q4. Why is Java not considered a pure object-oriented language?

Solution: Java is not considered a pure object-oriented language because it supports primitive data types (like int, char, boolean, etc.) which are not objects.