标签:code div style ring string int public this str
什么是构造方法呢?
就是方法名和你的类名一样
1 public class Student{ 2 3 private String name; 4 5 private int age; 6 7 //无参 8 9 public Student(){} 10 //有参 11 12 public Student(String name,int age){ 13 14 this.name = name; 15 16 this.age = age; 17 } 18 }
。没有返回值,也不要,连void都可以不要。
注意
1.你要是不提供构造方法,系统会给你个无参的
2.如果你给了构造方法,我就不给你提供无参的啦
3.构造方法可重载,可以定义参数也可以不定义
标签:code div style ring string int public this str
原文地址:https://www.cnblogs.com/hws9967/p/12676446.html