一、选择题
- B
- A
- D
- B
- C
- AC
- A
- A
- BC
二、编程题
- 创建Person类和测试类
属性:名字(name),年龄(age),年级( grade)
方法:
无参无返回值的student方法,描述为:我是一名学生!
带参数(性别sex)的方法,描述为:我是一个**孩!(其中,**为传入参数)
无参无返回值的mySelf方法,介绍自己的姓名、年龄、年级(参数参考效果图)
public class Person {
public String name;
public int age;
public int grade;
public Person() {
System.out.println("我是无参构造器");
}
public void student() {
System.out.println("我是一名学生");
}
public void personSex(String sex) {
System.out.println("我是一名" + sex +"孩");
}
public void mySelf(String name, int age, int grade) {
System.out.println("我叫" + name + "今年:" + age + "岁,是"+grade+"年级的学生");
}
}
//测试类
import java0506.Person;
public class Test {
public static void main(String[] args) {
Person p1 = new Person();
p1.student();
p1.personSex("男");
p1.mySelf("张三",18,5);
}
}
public class Monkey {
public String name;
public String feature;
public Monkey(){
this.name = "长尾猴";
this.feature = "尾巴长";
System.out.println("我是无参构造产生的猴子");
System.out.println("名称"+ this.name);
System.out.println("名称"+ this.feature);
}
public Monkey(String name, String feature) {
this.name = name;
this.feature = feature;
System.out.println("我是带参构造产生的猴子");
System.out.println("名称"+ this.name);
System.out.println("名称"+ this.feature);
}
}
//测试类
import java0506.Monkey;
public class Test {
public static void main(String[] args) {
Monkey mon = new Monkey();
Monkey mon1 = new Monkey("白头叶猴", "头上有白毛,喜欢吃树叶");
}
}