Skip to content
Sharp

Core Java · interview question

You have a method calculateShippingCost() that takes multiple parameters related to an order. What refactoring approach should you consider?

Multiple choiceMediumchapter-2-curatedpremiumcore-javacode-reading-and-refactoring-to-objects
Choose one answer
Answer and explanation

Correct answer

D. Create an Order class to encapsulate all related parameters.

Why

Encapsulating related data into an Order class allows for better organization, maintenance, and scalability of the code. It also aligns with object-oriented principles.

Test yourself on Core Java

A free test with instant, explained results. No account needed.

Start free test
All Core Java questions →