• JAVA第四次作业


    1.设计一个Dog类,有名字、颜色、年龄等属性,定义构造方法来初始化类的这些属性,定义方法输出Dog信息,编写应用程序使用Dog类。

    public class Dog {
    private String name;
    private String color;
    private int age;
    public Dog(String name, String color, int age) {
    this.name = name;
    this.color = color;
    this.age = age;
    }
    public void print() {
    System.out.print("名字: " + this.name + " " + "颜色:" + this.color + " "
    + "年龄:" + this.age);
    }
    public String getName() {
    return name;
    }
    public void setName(String name) {
    this.name = name;
    }
    public String getColor() {
    return color;
    }
    public void setColor(String color) {
    this.color = color;
    }
    public int getAge() {
    return age;
    }
    public void setAge(int age) {
    this.age = age;
    }
    }

    2. 设计一个表示用户的User类,中的变量有用户名、口令和记录用户个数的变量,定义类的3构造方法(无参、为用户名赋值、为用户名和口令赋值)获取和设置口令的方法和返回信息的方法。

    public class User {
    private String name;
    private String password;
    private static int num;
    public User() {
    num++;
    }
    public User(String name) {
    this.name = name;
    num++;
    }
    public User(String name, String password) {
    this.name = name;
    this.password = password;
    num++;
    }
    public void print() {
    System.out.print("用户个数:" + num + " ");
    System.out.println("名字: " + name + " " + "口令:" + password + " ");
    }
    public String getName() {
    return name;
    }
    public void setName(String name) {
    this.name = name;
    }
    public String getPassword() {
    return password;
    }
    public void setPassword(String password) {
    this.password = password;
    }
    }

  • 相关阅读:
    kubernetes部署Ingress Controller创建证书
    污点和容忍度
    Kubernetes部署coredns
    python中私有属性和私有方法
    类的约束
    reactjs 入门
    angularjs ngTable -Custom filter template-calendar
    sql 中条件in参数问题
    详解 nginx location ~ .*.(js|css)?$ 什么意思?
    CentOS 7.2.1511编译安装Nginx1.10.1+MySQL5.7.14+PHP7.0.11
  • 原文地址:https://www.cnblogs.com/xutingfeng/p/6599287.html
Copyright © 2020-2023  润新知