zoukankan      html  css  js  c++  java
  • Person类中多个构造方法和测试

     

    public class Person {
    String name="无名";//昵称
    String sex="man";//姓别
    /**
    * 无参构造方法
    */
    public Person() {
    name="山姆";
    sex="男";
    System.out.println("执行构造方法");
    }
    /**
    * 一个参数的构造方法
    */
    public Person(String name) {
    this.name=name;
    }
    /**
    * 二个参数的构造方法
    */
    public Person(String name,String sex) {
    this.name=name;
    this.sex=sex;
    }
    /**
    * 输出Person的信息
    */
    public void print() {
    System.out.println("persons的自由: 我的昵称叫:"+this.name+",性别是"+this.sex+"。");
    }
    *********************************************************************************************************************************

    public class TestPerson {

    public static void main(String[] args) {
    Person person=null;
    person=new Person();
    person.print();
    person=new Person("詹姆斯");
    person.print();
    person=new Person("爱丽丝","女");
    person.print();
    }
    }

  • 相关阅读:
    6_java_maven
    线性代数 linear algebra
    hadoop_wordcount_1027
    hadoop_worddistinct_1030
    hadoop_wordcount_1023
    搭建伪分布式_笔记
    linux-sunrpc
    linux-volatile
    linux---asmlinkage
    dqs_linux-1
  • 原文地址:https://www.cnblogs.com/zhang111/p/11993615.html
Copyright © 2011-2022 走看看