1.
public class Animal {
public String type;
public int weight;
public void shape(){
System.out.println("品种为"+type);
System.out.println("体重为"+weight);
}
public Animal(){
}
public Animal(String sound){
System.out.println("叫声为"+sound);
}
}
public class Cat {
public static void main(String[] args) {
Animal cat = new Animal("喵");
cat.type = "折耳猫";
cat.weight = 8;
cat.shape();
}
}
2.
public class Person2 {
String name;
String sex;
int age;
double height;
double weight;
String theory;
public void sound(){
System.out.println("大家好!");
}
public void say(){
System.out.println("我叫"+name+",今年"+age);
System.out.println("我是一个身高"+height+",体重"+weight+"的"+sex);
System.out.println(name+"的工作理念是"+theory);
}
public Person2(){
}
public Person2(String name,int age,double height,double weight,String sex){
this.name=name;
this.age=age;
this.height=height;
this.weight=weight;
this.sex=sex;
}
}
public class Person2Test {
public static void main(String[] args) {
Person2 abao = new Person2("阿宝",25,175.0,120.0,"男人");
abao.say();
Person2 meimei = new Person2("美美",21,165.0,100.0,"女人");
meimei.theory="工作是为了更好的生活";
meimei.say();
}
}