Home > Back-end >  Which bosses can help help me ~ ~ I'm going to write to cry
Which bosses can help help me ~ ~ I'm going to write to cry

Time:09-21

Java code
Write a class S (set, name the class name must have actual meaning), requirements:
1. The member variables: A1, A2, A3 (has practical significance to)
Methods: 2. Members B method, responsible for the output class A1, A2 and A3 attribute
3. With two constructors with parameters:
The first constructor, set the value of the attribute A1, the rest of the attribute's value by the parameter given;
The second constructor, all properties are given by the parameter,
4. Write a test class Test02 test, the above two methods of structure of two S class object is initialized,
And call their B method respectively,

CodePudding user response:

 
Public class Person {
//name
private String name;

//age
private int age;

//gender
Private int sex;

Public String printInfo () {
Return "name=" + name + ", the age="+ age +", sex="+ sex;
}

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

Public Person (String name, int the age, int sex) {
this.name=name;
this.age=age;
This. Sex=0;
}

}

CodePudding user response:

Create a Person class,
Package com. Xiaolige. The entity;

Public class Person {
private String name;
private int age;
Private String sex;

//the first constructor, set the A1 attribute's value, the rest of the attribute's value given by the parameter;
Public Person (int the age, the String sex) {
super();
this.age=age;
this.sex=sex;
}
//the second constructor, all properties are given by the parameter,
Public Person (String name, int the age, the String sex) {
super();
this.name=name;
this.age=age;
this.sex=sex;
}

Public void personInfo (Person to Person) {
System. The out. Println (" the attribute of the Person is: "+ Person. Name + Person. Age + Person. Sex);
}




Public String getName () {
return name;
}
Public void elegantly-named 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;
}


}

Create a test class Test01 call execution method,
Package com. Xiaolige. Test;

The import com. Xiaolige. Entity. The Person;

Public class Test01 {

Public static void main (String [] args) {
The Person the Person=new Person (18, "female");
Person. Elegantly-named setName (" Ada ");
Person. PersonInfo (person);

Person p2=new Person (" Yang ", 19, "female");
P2. PersonInfo (p2);
}
}
Output;
Person's property to: Ada 18 female
Person's property to: Yang mi 19 female

CodePudding user response:

Thank you for your bosses ~

CodePudding user response:

@ Data
Public class S {

Private String A1.
Private String A2;
Private String A3;

The public S (String A2, String A3) {
This (" 1 ", A2, A3);
}

The public S (String A1, String A2, String A3) {
This. A1=A1;
This. A2=A2;
This. A3=A3;
}

Public static void main (String [] args) {
S=new S final S (" 2 ", "3");
System.out.println(s);
}
}

CodePudding user response:

Μ r. eta ob &western dy, positive solutions to points ",
  • Related