12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849 |
- package com.sf.day08;
- public class Person {
- public String name;
- public int age;
- /**
- * 构造器的作用 : 对象的创建 属性的赋值
- *创建无参构造器 有参构造器
- */
- public double weight;
- public Person(){
- }
- public Person(int age ){
- this.age = age;
- }
- public Person(String name,int age ){
- this.name = name;
- this.age = age;
- }
- public Person(String name,int age,double weight ){
- this(name,age);
- this.weight = weight;
- }
- @Override
- public String toString() {
- return "Person{" +
- "name='" + name + '\'' +
- ", age=" + age +
- ", weight=" + weight +
- '}';
- }
- public static void main(String[] args) {
- // Person person = new Person(13);
- Person person1 = new Person("zs", 13, 123.0);
- System.out.println(person1);
- }
- }
|