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);
}
}
About Question enthuware.ocajp.i.v8.2.875 :
Moderator: admin
-
- Posts: 2
- Joined: Wed Aug 03, 2022 5:08 pm
- Contact:
-
- Posts: 2
- Joined: Wed Aug 03, 2022 5:08 pm
- Contact:
-
- Site Admin
- Posts: 10065
- Joined: Fri Sep 10, 2010 9:26 pm
- Contact:
Re: About Question enthuware.ocajp.i.v8.2.875 :
>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.
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.
Who is online
Users browsing this forum: Bing [Bot] and 106 guests