zoukankan      html  css  js  c++  java
  • 继承

    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();

    }

    }

  • 相关阅读:
    sql处理数据库锁的存储过程
    SQL语句
    partial 函数
    map函数
    python命令行上下 退格,左右键不能用
    postgresql 在linux上的源码安装
    python字典操作
    根据key存不存在查询json
    精典博文
    python解析XML之ElementTree
  • 原文地址:https://www.cnblogs.com/zaoxi11/p/6026350.html
Copyright © 2011-2022 走看看