1z0-808 Exam QuestionsBrowse all questions from this exam

1z0-808 Exam - Question 1


Given:

What is the result?

Show Answer
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

17 comments
Sign in to comment
hyodaeunOption: C
Jan 17, 2019

Answer is c

see_meee_johnsonOption: C
Apr 23, 2024

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

Def8Option: C
Oct 28, 2022

Objects are pass by reference

masloaOption: C
Mar 23, 2023

Objects are pass by reference, primitives passed by value

Vicky_65Option: C
Apr 1, 2023

Answer is C

felipegomeztreufoOption: C
May 25, 2023

Answer is C

NabilBenAskerOption: C
Jul 4, 2023

Answer is C

Thando_4Option: C
Jul 10, 2023

Answer is C

dsmsOption: C
Aug 12, 2023

Answer is: 400.0 : 100.0

SezamOption: C
Aug 20, 2023

Answer is C

Drift_KingOption: C
Aug 28, 2023

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); } }

veer684Option: C
Sep 2, 2023

Answer is C

OndoOption: C
Sep 17, 2023

Réponse C

gg7495Option: C
Sep 17, 2023

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

YukiSatohOption: C
Oct 12, 2023

Selected Answer: C

Dibya17Option: C
Jan 16, 2024

Answer is C

nurayOption: A
Feb 4, 2024

A. 200.0 : 100.0