public class Cart {
private String id;
private List<RentedMovie> rentedMovies = new ArrayList<RentedMovie>();
private long totalRent;
private long cartItemsCount;
public Cart(Cart sessionCart) {
this.id = sessionCart.id;
this.rentedMovies = sessionCart.rentedMovies;
this.totalRent = sessionCart.totalRent;
this.cartItemsCount = sessionCart.cartItemsCount;
}
..<Getters and setters of all private varibles>..
}
I am little bit confused with my constructor concepts in java. In the above sample code, I have declared one Cart constructor which is having argument as Cart (that can be referring to another Cart object). As we can see in the sample class, all the instance variables are private, how can I able to access the private variables of Cart class via reference sessionCart directly. Ideally I should not be able to.
Please help.