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)
- What is dynamic method dispatch in Java?Multiple choiceEasy
- What does the following code snippet demonstrate about variable scope in Java?Multiple choiceMedium
- What issue might arise from using 'float' to store product prices in a Java e-commerce application?Multiple choiceHard
- Consider the following code. What will be printed to the console?Multiple choiceHard
- Why should you be cautious when relying on autoboxing and unboxing in performance-critical code?Multiple choiceMedium
- How would you explain a significant advantage of using local variables over global variables in methods in an interview?Multiple choiceMedium
- 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
- 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
- Given the following code snippet, what outcome should you expect?Multiple choiceMedium
- Why does upcasting an object in terms of method accessibility change runtime behavior?Multiple choiceMedium
- In an order-processing system, which design consideration justifies creating a custom exception?Multiple choiceHard
- What happens when an exception is thrown and not caught in a method?Multiple choiceEasy
- Which of the following expressions correctly applies a 15% discount to a product's price stored in 'price'?Multiple choiceMedium
- In a checkout system, how should exceptions be handled to ensure the system remains reliable?Multiple choiceHard
- 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
- What does the expression '50 + 30 * 2' in Java evaluate to?Multiple choiceMedium
- In which scenario should you catch an exception rather than propagate it?Multiple choiceMedium
- Which of the following is a potential issue when using wrapper types instead of primitives in Java?Multiple choiceEasy
- 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
- Which scenario could lead to unexpected behavior due to autoboxing when summing elements in a List<Integer>?Multiple choiceHard
- What happens when this try/catch handles division by zero with the wrong exception type?Multiple choiceHard
- Which of the following is a potential issue when using 'double' for product prices in a Java e-commerce application?Multiple choiceHard
- Why do teams use interfaces in Java in production code?Multiple choiceEasy
- Given 'boolean isAvailable =!(stock < 5);', what is 'isAvailable' if stock is 3?Multiple choiceMedium
- Which code correctly update the price of a product stored in a double variable?Multiple choiceMedium
- Given the following method signature, what is the responsibility of the caller regarding exception handling?Multiple choiceHard
- 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
- In a checkout process, which type of exception should be used for a missing payment method?Multiple choiceMedium
- How can autoboxing lead to a subtle bug when comparing Integer objects using '=='?Multiple choiceHard
- 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
- Which approach is the best fit to store a product's SKU (Stock Keeping Unit) in Java?Multiple choiceMedium
- Why does upcasting an object to a superclass type change runtime behavior?Multiple choiceEasy
- Which of the following variable names is the most appropriate for storing a discount rate as a decimal?Multiple choiceMedium
- What does calling a method that throws an unchecked exception without handling it evaluate to?Multiple choiceEasy
- How does parameter scope limit what can be done in a method?Multiple choiceMedium
- Why is it beneficial to use abstract classes in Java?Multiple choiceMedium
- In Java, what is the best way to declare a variable for a product's name?Multiple choiceMedium
- How can you ensure that a resource is closed after use, even if an exception occurs?Multiple choiceMedium
- You need to store and calculate prices with high precision. Which data type should you choose and why?Multiple choiceHard
- Why might the following code result in a compilation error? abstract class Service { abstract void execute(); } class Shipping extends Service { void…Multiple choiceHard
- In Java, what is the relationship between an interface and a class that implements it?Multiple choiceEasy
- Why is it useful to upcasting in Java?Multiple choiceEasy
- Why does catching an exception and not rethrowing it change runtime behavior?Multiple choiceMedium
- Given the following code, what will be the output and why?Multiple choiceHard
- Which statement about interfaces in Java is correct?Multiple choiceEasy
- How would you explain the hidden danger in Integer quantity = null; int count = quantity; in an interview?Multiple choiceEasy
- Why can separate variables like subtotal, discountedTotal, and finalTotal be better than reusing one total variable for everything?Multiple choiceHard
- Which of the following scenarios could lead to a NullPointerException when using Integer objects?Multiple choiceHard
- In Java, what is the result of calling an overridden method on a subclass object when referenced via a superclass type?Multiple choiceMedium
- Why is it important to avoid reassigning a method parameter inside the method when calculating a discount?Multiple choiceMedium