2条回答 默认 最新
- 彭大哥学编程 2021-06-09 14:54关注
class Monkey { String name; String feature; Monkey() { System.out.println("我是使用无参构造产生的猴子:"); this.name = "长尾猴"; this.feature = "尾巴长"; } Monkey(String name, String feature) { System.out.println("我是使用带参构造产生的猴子:"); this.name = name; this.feature = feature; } } public class Test{ public static void main(String []args) { Monkey monkey1 = new Monkey(); System.out.println("名称:" + monkey1.name); System.out.println("特征:" + monkey1.feature); System.out.println("==========================="); Monkey monkey2 = new Monkey("白头叶猴", "头上有白毛,喜欢吃树叶"); System.out.println("名称:" + monkey2.name); System.out.println("特征:" + monkey2.feature); } }
本回答被题主选为最佳回答 , 对您是否有帮助呢?解决 1无用