Student s1 =new Student(); 系统分配的构造器
public Student(){ 直接和new语句绑定使用
sout
}
Student stu = new Student(); 位于另一个class
带参构造器,一次性完成赋值
this.属性 = 形参; 我的当前对象 = 你传过来的
Student s2 = new Student(2,"李四",22,98);
s2.sayHi(); 少些会报错,实参与形参要一一对应
带参构造器 快捷键:
右键→source→Construction Using Field…
Product pro = new Product(name,price,number);
cart.push(pro) ←→ cart.push(name,price,number)
Public void search(String name)
Public void search(String name , int begin , int end )
构成方法重载:同一类中,多个方法 方法名称相同 参数不同
作用是:解决同一个操作 在不同情况下 有不同的实现代码
sout
也是方法重载
放外面 → 成员变量
(会默认给值)
放里面 → 局部变量
(不默认给值)
优先级:局部
> 成员
要在 局部
里使用 成员
同名下,用 this
{this.number = number}