Skip to content
Sharp

Object-oriented programming · interview question

What would be the result of calling product.updatePrice(50) with the code provided?

Multiple choiceMediumchapter-2-curatedpremiumoopinstance-methods
java
class Product {
    private double price;
    public void updatePrice(double newPrice) {
        this.price = newPrice;
    }
}
Choose one answer
Answer and explanation

Correct answer

A. The product's price would be set to 50.

Why

The updatePrice method directly sets the price to the passed value of 50, updating the product's price.

Test yourself on Object-oriented programming

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

Start free test
All Object-oriented programming questions →