引用数据中类型变量访问
package com.itcast.cn; public class test01 { public static void main(String[] args) { Address address = new Address(180); User user = new User(address); //等同于 User user = new User(new Address(180)); user.address.setShenGao(180); int shenGao = user.address.getShenGao(); System.out.println(shenGao); } } class User { Address address; public User(Address address) { this.address = address; } public Address getAddress() { return address; } public void setAddress(Address address) { this.address = address; } public User() { } } class Address { private int shenGao; public int getShenGao() { return shenGao; } public void setShenGao(int shenGao) { this.shenGao = shenGao; } public Address() { } public Address(int shenGao) { this.shenGao = shenGao; } }