哪位大佬能帮帮忙吗~~我快写哭了

Sxn16056 2020-05-30 03:02:27
Java代码
编写一个类S(具体名称自定,类名称必须要有实际的意义),要求:
1.成员变量:A1、A2、A3(要有实际的意义)
2.成员方法:B方法,负责输出该类对象的A1、A2及A3属性
3.具有两个带参数的构造方法:
第一个构造方法中,设置A1属性的值,其余属性的值由参数给定;
第二个构造方法中,所有属性都由参数给定。
4.编写测试类Test02进行测试,分别用以上两种构造方法对两个S类对象进行初始化,
并分别调用他们的B方法。

...全文
185 5 打赏 收藏 转发到动态 举报
写回复
用AI写文章
5 条回复
切换为时间正序
请发表友善的回复…
发表回复
Sxn16056 2020-06-01
  • 打赏
  • 举报
回复
谢谢大佬们~
zhtoad 2020-06-01
  • 打赏
  • 举报
回复
Μr.ηobοdy 正解。给分结帖。
梦在明月 2020-06-01
  • 打赏
  • 举报
回复
@Data public class S { private String A1; private String A2; private String A3; public S(String A2, String A3) { this("1", A2, A3); } public S(String A1, String A2, String A3) { this.A1 = A1; this.A2 = A2; this.A3 = A3; } public static void main(String[] args) { final S s = new S("2", "3"); System.out.println(s); } }
Joker_lzm 2020-05-31
  • 打赏
  • 举报
回复
创建Person类,
package com.xiaolige.entity;

public class Person {
private String name;
private int age;
private String sex;

// 第一个构造方法中,设置A1属性的值,其余属性的值由参数给定;
public Person(int age, String sex) {
super();
this.age = age;
this.sex = sex;
}
// 第二个构造方法中,所有属性都由参数给定。
public Person(String name, int age, String sex) {
super();
this.name = name;
this.age = age;
this.sex = sex;
}

public void personInfo(Person person) {
System.out.println("Person的属性为:"+person.name+person.age+person.sex);
}




public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public int getAge() {
return age;
}
public void setAge(int age) {
this.age = age;
}
public String getSex() {
return sex;
}
public void setSex(String sex) {
this.sex = sex;
}


}

创建测试类Test01 调用执行方法,
package com.xiaolige.test;

import com.xiaolige.entity.Person;

public class Test01 {

public static void main(String[] args) {
Person person = new Person(18, "女");
person.setName("柳岩");
person.personInfo(person);

Person p2 = new Person("杨幂",19,"女");
p2.personInfo(p2);
}
}
输出;
Person的属性为:柳岩18女
Person的属性为:杨幂19女
陈皮的JavaLib 2020-05-31
  • 打赏
  • 举报
回复

public class Person {
    // 名字
    private String name;

    // 年龄
    private int age;

    // 性别
    private int sex;

    public String printInfo() {
        return "name=" + name + ", age=" + age + ", sex=" + sex;
    }

    public Person(String name, int age, int sex) {
        this.name = name;
        this.age = age;
        this.sex = sex;
    }

   public Person(String name, int age, int sex) {
        this.name = name;
        this.age = age;
        this.sex = 0;
    }

}

58,452

社区成员

发帖
与我相关
我的任务
社区描述
Java Eclipse
社区管理员
  • Eclipse
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧