Exam 1z0-808 All QuestionsBrowse all questions from this exam
Question 1

Given:

What is the result?

    Correct Answer: C

    The code demonstrates the difference between passing objects and primitive values in Java. In Java, objects (like 'Product' here) are passed by reference, meaning changes to the object's properties remain after the method call. On the other hand, primitive data types (like 'double' here) are passed by value, meaning changes to the variable inside the method do not affect the original value. Within the 'updatePrice' method, 'price' is a local variable and multiplying it by 2 doesn't affect the original 'newPrice' value. However, 'product.price' is updated through its reference. Initially, 'product.price' is 200. After calling 'updatePrice', 'product.price'+price' becomes 200+200 = 400. Therefore, the output is 'product.price: 400.0' and 'newPrice: 100.0', resulting in '400.0 : 100.0'.

Discussion
hyodaeunOption: C

Answer is c

see_meee_johnsonOption: C

Answer - (c) as newPrice variable is not getting updated. The instance variable price is getting updated https://shorter.me/JavaSE8ProgrammerI

nurayOption: A

A. 200.0 : 100.0

Dibya17Option: C

Answer is C

YukiSatohOption: C

Selected Answer: C

gg7495Option: C

Answer - (c) as newPrice variable is not getting updated. The instance variable price is getting updated

OndoOption: C

Réponse C

veer684Option: C

Answer is C

Drift_KingOption: C

Tested. Answer is C: 400.0 : 100.0 class Product{ double price; } public class Test { public void updatePrice(Product product, double price){ price = price*2; product.price = product.price + price; } public static void main(String args[]) { Product prt = new Product(); prt.price = 200; double newPrice = 100; Test t = new Test(); t.updatePrice(prt, newPrice); System.out.println(prt.price+ " : "+newPrice); } }

SezamOption: C

Answer is C

dsmsOption: C

Answer is: 400.0 : 100.0

Thando_4Option: C

Answer is C

NabilBenAskerOption: C

Answer is C

felipegomeztreufoOption: C

Answer is C

Vicky_65Option: C

Answer is C

masloaOption: C

Objects are pass by reference, primitives passed by value

Def8Option: C

Objects are pass by reference