From dfe444436d4a655f012d5eb49697b9f26335578e Mon Sep 17 00:00:00 2001 From: Ryan <1572382023@qq.com> Date: Tue, 29 Mar 2022 23:20:38 +0800 Subject: [PATCH 1/2] =?UTF-8?q?=E6=88=91=E5=B7=B2=E5=AE=8C=E6=88=90?= =?UTF-8?q?=E9=87=8D=E8=BD=BD=E6=9E=84=E9=80=A0=E5=99=A8=E4=BD=9C=E4=B8=9A?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/com/github/hcsp/objectbasic/Cat.java | 37 ++++++++++++++++--- 1 file changed, 31 insertions(+), 6 deletions(-) diff --git a/src/main/java/com/github/hcsp/objectbasic/Cat.java b/src/main/java/com/github/hcsp/objectbasic/Cat.java index c9d7663..0afb4ae 100644 --- a/src/main/java/com/github/hcsp/objectbasic/Cat.java +++ b/src/main/java/com/github/hcsp/objectbasic/Cat.java @@ -1,27 +1,52 @@ package com.github.hcsp.objectbasic; public class Cat { - /** 猫咪的名字 */ + /** + * 猫咪的名字 + */ String name; - /** 猫咪的年龄 */ + /** + * 猫咪的年龄 + */ int age; - /** 猫咪是否萌,true为萌,false为不萌 */ + /** + * 猫咪是否萌,true为萌,false为不萌 + */ boolean cute; - /** 创建一只指定名字的猫,age的默认值是1,cute的默认值是true */ + /** + * 创建一只指定名字的猫,age的默认值是1,cute的默认值是true + */ public Cat(String name) { // 请在这里使用this()调用其他的构造器 + this(name, 1, true); } - /** 创建一只指定名字和年龄的猫,cute的默认值是true */ + /** + * 创建一只指定名字和年龄的猫,cute的默认值是true + */ public Cat(String name, int age) { // 请在这里使用this()调用其他的构造器 + this.name = name; + this.age = age; } - /** 创建一只指定名字、年龄和萌属性的猫 */ + /** + * 创建一只指定名字、年龄和萌属性的猫 + */ public Cat(String name, int age, boolean cute) { this.name = name; this.age = age; this.cute = cute; } + + public Cat() { + int age=1; + String name="咪咪"; + boolean cute=true; + } + + public static void main(String[] args) { + new Cat(); + } } From c6f375c20b8d3834ccd5f843156cae58a3c961ab Mon Sep 17 00:00:00 2001 From: Ryan <1572382023@qq.com> Date: Wed, 30 Mar 2022 01:34:36 +0800 Subject: [PATCH 2/2] =?UTF-8?q?=E6=88=91=E5=B7=B2=E5=AE=8C=E6=88=90?= =?UTF-8?q?=E9=87=8D=E8=BD=BD=E6=9E=84=E9=80=A0=E5=99=A8=E4=BD=9C=E4=B8=9A?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/java/com/github/hcsp/objectbasic/Cat.java | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/main/java/com/github/hcsp/objectbasic/Cat.java b/src/main/java/com/github/hcsp/objectbasic/Cat.java index 0afb4ae..8820ae4 100644 --- a/src/main/java/com/github/hcsp/objectbasic/Cat.java +++ b/src/main/java/com/github/hcsp/objectbasic/Cat.java @@ -41,9 +41,9 @@ public Cat(String name, int age, boolean cute) { } public Cat() { - int age=1; - String name="咪咪"; - boolean cute=true; + int age = 1; + String name = "咪咪"; + boolean cute = true; } public static void main(String[] args) {