java0506作业

一、选择题

  1. B
  2. A
  3. D
  4. B
  5. C
  6. AC
  7. A
  8. A
  9. BC

二、编程题

  1. 创建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("白头叶猴", "头上有白毛,喜欢吃树叶");
    }

}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值