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 9 of 10)

  1. What is dynamic method dispatch in Java?Multiple choiceEasy
  2. What does the following code snippet demonstrate about variable scope in Java?Multiple choiceMedium
  3. What issue might arise from using 'float' to store product prices in a Java e-commerce application?Multiple choiceHard
  4. Consider the following code. What will be printed to the console?Multiple choiceHard
  5. Why should you be cautious when relying on autoboxing and unboxing in performance-critical code?Multiple choiceMedium
  6. How would you explain a significant advantage of using local variables over global variables in methods in an interview?Multiple choiceMedium
  7. In a method calculating a product's final price, what happens if you attempt to use a variable declared inside an if block outside of it?Multiple choiceEasy
  8. In Java, what is the result of calling a method on a superclass reference that points to a subclass object if the method is overridden in the subclass?Multiple choiceMedium
  9. Given the following code snippet, what outcome should you expect?Multiple choiceMedium
  10. Why does upcasting an object in terms of method accessibility change runtime behavior?Multiple choiceMedium
  11. In an order-processing system, which design consideration justifies creating a custom exception?Multiple choiceHard
  12. What happens when an exception is thrown and not caught in a method?Multiple choiceEasy
  13. Which of the following expressions correctly applies a 15% discount to a product's price stored in 'price'?Multiple choiceMedium
  14. In a checkout system, how should exceptions be handled to ensure the system remains reliable?Multiple choiceHard
  15. How would you explain the behavior of the '==' operator when comparing Integer objects within the range of -128 to 127 in an interview?Multiple choiceMedium
  16. What does the expression '50 + 30 * 2' in Java evaluate to?Multiple choiceMedium
  17. In which scenario should you catch an exception rather than propagate it?Multiple choiceMedium
  18. Which of the following is a potential issue when using wrapper types instead of primitives in Java?Multiple choiceEasy
  19. Consider a method that uses a for loop to calculate the total price of items. What is the scope of a loop control variable in this context?Multiple choiceMedium
  20. Which scenario could lead to unexpected behavior due to autoboxing when summing elements in a List<Integer>?Multiple choiceHard
  21. What happens when this try/catch handles division by zero with the wrong exception type?Multiple choiceHard
  22. Which of the following is a potential issue when using 'double' for product prices in a Java e-commerce application?Multiple choiceHard
  23. Why do teams use interfaces in Java in production code?Multiple choiceEasy
  24. Given 'boolean isAvailable =!(stock < 5);', what is 'isAvailable' if stock is 3?Multiple choiceMedium
  25. Which code correctly update the price of a product stored in a double variable?Multiple choiceMedium
  26. Given the following method signature, what is the responsibility of the caller regarding exception handling?Multiple choiceHard
  27. In the context of a method that calculates the total price of items in a cart, what happens when a local variable is reassigned within the method?Multiple choiceEasy
  28. In a checkout process, which type of exception should be used for a missing payment method?Multiple choiceMedium
  29. How can autoboxing lead to a subtle bug when comparing Integer objects using '=='?Multiple choiceHard
  30. In an e-commerce application, which data type is the most appropriate for storing a product's price when precise calculations involving currency are needed?Multiple choiceMedium
  31. Which approach is the best fit to store a product's SKU (Stock Keeping Unit) in Java?Multiple choiceMedium
  32. Why does upcasting an object to a superclass type change runtime behavior?Multiple choiceEasy
  33. Which of the following variable names is the most appropriate for storing a discount rate as a decimal?Multiple choiceMedium
  34. What does calling a method that throws an unchecked exception without handling it evaluate to?Multiple choiceEasy
  35. How does parameter scope limit what can be done in a method?Multiple choiceMedium
  36. Why is it beneficial to use abstract classes in Java?Multiple choiceMedium
  37. In Java, what is the best way to declare a variable for a product's name?Multiple choiceMedium
  38. How can you ensure that a resource is closed after use, even if an exception occurs?Multiple choiceMedium
  39. You need to store and calculate prices with high precision. Which data type should you choose and why?Multiple choiceHard
  40. Why might the following code result in a compilation error? abstract class Service { abstract void execute(); } class Shipping extends Service { void…Multiple choiceHard
  41. In Java, what is the relationship between an interface and a class that implements it?Multiple choiceEasy
  42. Why is it useful to upcasting in Java?Multiple choiceEasy
  43. Why does catching an exception and not rethrowing it change runtime behavior?Multiple choiceMedium
  44. Given the following code, what will be the output and why?Multiple choiceHard
  45. Which statement about interfaces in Java is correct?Multiple choiceEasy
  46. How would you explain the hidden danger in Integer quantity = null; int count = quantity; in an interview?Multiple choiceEasy
  47. Why can separate variables like subtotal, discountedTotal, and finalTotal be better than reusing one total variable for everything?Multiple choiceHard
  48. Which of the following scenarios could lead to a NullPointerException when using Integer objects?Multiple choiceHard
  49. In Java, what is the result of calling an overridden method on a subclass object when referenced via a superclass type?Multiple choiceMedium
  50. Why is it important to avoid reassigning a method parameter inside the method when calculating a discount?Multiple choiceMedium