编程语言
首页 > 编程语言> > Java自学习day10-属性赋值的先后顺序

Java自学习day10-属性赋值的先后顺序

作者:互联网

属性赋值的先后顺序

以上操作的先后顺序:① - ② - ③ - ④

public class UserTest {
	public static void main(String[] args) {
		User u = new User();
		
		System.out.println(u.age);
		
		User u1 = new User(2);
		
		u1.setAge(3);
		u1.setAge(5);
		
		System.out.println(u1.age);
	}
}

class User{
	String name;
	int age = 1;
	
	public User(){
		
	}
	
	public User(int a){
		age = a;
	}
	
	public void setAge(int a){
		age = a;
	}
	
}

标签:先后顺序,Java,int,age,u1,setAge,day10,User,public
来源: https://blog.csdn.net/KO812605128/article/details/116402351