About Question enthuware.ocajp.i.v8.2.875 :

Help and support on OCA OCP Java Programmer Certification Questions
1Z0-808, 1Z0-809, 1Z0-815, 1Z0-816, 1Z0-817

Moderator: admin

Post Reply

Omranhariri
Posts: 2
Joined: Wed Aug 03, 2022 5:08 pm
Contact:

Re: About Question enthuware.ocajp.i.v8.2.875 :

Post by Omranhariri »

class Data {

int intVal = 0;
String strVal = "default";
public Data(int k){
this.intVal = k;
}

}

public class TestClass {
public static void main(String[] args) throws Exception {
Data d1 = new Data(10);
d1.strVal = "D1";
Data d2 = d1;
d2.intVal = 20; // is here a new Objekt has been created?!
System.out.println("d2 val = "+d2.strVal);
}
}

admin
Site Admin
Posts: 10036
Joined: Fri Sep 10, 2010 9:26 pm
Contact:

Re: About Question enthuware.ocajp.i.v8.2.875 :

Post by admin »

>d2.intVal = 20; // is here a new Objekt has been created?!

No. intVal is a primitive field of the existing object of class D2 pointed to by the variable d2. This field is being assigned a new int value of 20 here.
If you like our products and services, please help us by posting your review here.

Post Reply

Who is online

Users browsing this forum: Google [Bot], marpiva and 53 guests