AllInfoHub Logo

AllInfoHub – MCQ Practice

Variables and Data Types – Multiple Choice Questions (MCQs)

  1. 13. What is the default value of a reference data type in Java?

    • A. 0
    • B. null
    • C. undefined
    • D.
  2. 14. Which keyword is used to declare a variable as a constant in Java?

    • A. const
    • B. immutable
    • C. readonly
    • D. final
  3. 15. What is the scope of a local variable in Java?

    • A. Accessible from anywhere in the class
    • B. Accessible only within the method where it is declared
    • C. Accessible within the same package
    • D. Accessible within the same class
  4. 16. What is the scope of an instance variable in Java?

    • A. Accessible only within the method where it is declared
    • B. Accessible only within the class where it is declared
    • C. Accessible to all instances of the class
    • D. Accessible within the same package
  5. 17. What is the scope of a static variable in Java?

    • A. Accessible only within the method where it is declared
    • B. Accessible only within the class where it is declared
    • C. Accessible to all instances of the class and the class itself
    • D. Accessible within the same package
  6. 18. Which of the following is a valid variable declaration in Java?

    • A. int x;
    • B. variable y = 10;
    • C. String "hello";
    • D. float 3.14f;
  7. 19. Which of the following is NOT a valid variable name in Java?

    • A. myVariable
    • B. _myVar
    • C. 1stVar
    • D. $myVar
  8. 20. What is type casting in Java?

    • A. Converting a primitive data type to a reference type
    • B. Converting a reference type to a primitive data type
    • C. Converting a value of one data type to another
    • D. Declaring a variable without assigning a value
  9. 21. What is implicit type casting (widening) in Java?

    • A. Casting from a larger data type to a smaller one
    • B. Casting from a smaller data type to a larger one
    • C. Casting between reference types
    • D. It is not allowed in Java
  10. 22. What is explicit type casting (narrowing) in Java?

    • A. Casting from a smaller data type to a larger one
    • B. Casting from a larger data type to a smaller one
    • C. Casting between primitive types
    • D. It happens automatically
  11. 23. Which operator is used for type casting in Java?

    • A. ()
    • B. []
    • C. {}
    • D. <>
  12. 24. What will be the result of `(int) 3.14`?

    • A. 3
    • B. 3
    • C. Error
    • D. 4