Skip to content
Sharp

Core Java interview questions

BigDecimal and Money, Code Reading and Debugging, Code Reading and Refactoring to Objects, Code Reading and State Safety, Code Reading with Collections, Code Reading with Exceptions

473 questions with answers and explanations · 472 flashcards

Questions (page 10 of 10)

  1. Which of the following statements correctly initializes a BigDecimal with a string value for a product price?Multiple choiceHard
  2. Why is it important to catch specific exceptions rather than general ones?Multiple choiceMedium
  3. Why might using a primitive type be preferable in performance-critical Java code?Multiple choiceEasy
  4. What does the following code snippet, assuming 'Integer.valueOf' is used evaluate to?Multiple choiceMedium
  5. Which statement is true regarding exception propagation?Multiple choiceEasy
  6. Why does an interface in Java matter in this design?Multiple choiceEasy
  7. Which keyword is used in Java to declare a constant for the maximum quantity of products?Multiple choiceEasy
  8. In a method calculating the shipping cost, where should you declare a variable to ensure it is not accessible outside the method?Multiple choiceEasy
  9. Consider the code snippet below. What will be the output when the divide method is called with a divisor of 0?Multiple choiceMedium
  10. What happens if you attempt to call a method that is not defined in the superclass using a superclass reference pointing to a subclass object?Multiple choiceMedium
  11. Which of the following statements is true regarding wrapper classes in Java?Multiple choiceEasy
  12. In the context of an e-commerce checkout method, what issue might arise from shadowing a method parameter with a local variable of the same name?Multiple choiceHard
  13. What will be the output of the following code involving polymorphism?Multiple choiceHard
  14. What does it mean when a method signature includes 'throws IOException'?Multiple choiceEasy
  15. Given the following code, which method will be executed at runtime? class Product { void display() { System.out.println("Product"); } } class Book extends…Multiple choiceMedium
  16. Why does the 'throw' keyword matter in practice?Multiple choiceMedium
  17. Which of the following data types is best for storing a product's stock quantity?Multiple choiceEasy
  18. Why does the following code not compile?Multiple choiceHard
  19. Which data type to store a product's SKU (Stock Keeping Unit) in Java is the best fit?Multiple choiceMedium
  20. If you incorrectly declare a product's price as 'double price = 19.99;', what kind of problem might you encounter in calculations?Multiple choiceHard
  21. If a method signature changes from using primitive int to Integer, what potential issue might arise?Multiple choiceHard
  22. In a Java application, how can you ensure that critical resources are released even if an exception occurs?Multiple choiceHard
  23. Which type is the cleanest fit for product quantity in a beginner checkout flow?Multiple choiceEasy