zoukankan      html  css  js  c++  java
  • 抽象与集继承

     1 package com.dengbao;
     2 
     3 public class DemoPerson {
     4 
     5     public static void main(String[] args) {
     6         Person student=new Student("旺财",3, 90.5f);
     7         Person worker=new Woker("小强",1, 8125.5f);
     8         Person student1=new Student("小黄",8, 1000f);
     9         Person worker1=new Woker("小刘",12, 18125.5f);
    10         print(student.speak());
    11         print(worker.speak());
    12         print(student1.speak());
    13         print(worker1.speak());
    14     }
    15     private static void print(String speak) {
    16         System.out.println(speak);
    17     }
    18 }
     1 package com.dengbao;
     2 
     3 public abstract class Person {
     4     private String name;
     5     private int age;
     6     public String getName() {
     7         return name;
     8     }
     9     public void setName(String name) {
    10         this.name = name;
    11     }
    12     public int getAge() {
    13         return age;
    14     }
    15     public void setAge(int age) {
    16         this.age = age;
    17     }
    18     public Person(String name, int age) {
    19         this.name = name;
    20         this.age = age;
    21     }
    22     public Person() {
    23         super();
    24     }
    25     @Override
    26     public String toString() {
    27         return "Person [name=" + name + ", age=" + age + "]";
    28     }
    29     public abstract String speak();
    30 }
     1 package com.dengbao;
     2 
     3 public class Student extends Person{
     4     private float score;
     5     
     6     public Student(String name, int age, float score) {
     7         super(name, age);
     8         this.setScore(score);
     9     }
    10     @Override
    11     public String speak() {
    12         return "学生说-->我的姓名:"+super.getName()+" "+super.getAge()+"岁 "+this.score+"分";
    13     }
    14     public float getScore() {
    15         return score;
    16     }
    17     public void setScore(float score) {
    18         this.score = score;
    19     }
    20 }

    This moment will nap, you will have a dream; but this moment study, you will interpret a dream.
  • 相关阅读:
    专为seo新手准备的百度分享工具教程
    什么是关键词权重
    什么是关键词堆砌
    什么是目标关键词
    华为SEO搜索引擎主管招聘内容
    长尾关键词是什么意思
    Java面试宝典(7)混合2
    SpringMVC学习(5):数据绑定2 @PathVariable、@CookieValue、@RequestHeader、@ModelAttribute..
    MyBatis中XML 映射配置文件的简单介绍
    最牛B的编码套路
  • 原文地址:https://www.cnblogs.com/mawenqi-barry/p/7855806.html
Copyright © 2011-2022 走看看