0

java

How many objects are created if you run the following Class? public class Question8 int num; public static void main(String[] args) { Question8 b=foo(); b.num=5; Question8 c=b; c.num=4; Object obj=c; Question8 d=foo(); d. num =b.num; private static Question too(){ return new Question8(); } }

28th Apr 2022, 8:11 AM
burçin özkan
2 RĂ©ponses
+ 1
burçin özkan Your code is not right, you have typing mistake. Only 2 object will be created. You can check by printing objects --- public class Question { int num; public static void main(String[] args) { Question b = foo(); System.out.println (b); b.num = 5; Question c = b; c.num = 4; System.out.println (c); Object obj = c; System.out.println(obj); Question d = foo(); System.out.println(d); d.num = b.num; } private static Question foo() { return new Question(); } }
28th Apr 2022, 8:19 AM
AÍąJ
AÍąJ - avatar
0
Thanks.
28th Apr 2022, 8:20 AM
burçin özkan