zoukankan      html  css  js  c++  java
  • java抽象类实践

    package javaClassStudy;
    
    /**
     *
     * @author yuxg
     * 抽象类实践
     */
    public abstract  class Person {
        private String name ;
        private int    age;
    
        public Person(String name, int age) {
            this.name = name;
            this.age = age;
        }
        
        public String getName() {
            return name;
        }
    
        public void setName(String name) {
            this.name = name;
        }
    
        public void setAge(int age) {
            this.age = age;
        }
    
        public int getAge() {
            return age;
        }
        public abstract String  getDescription();//描述
        public abstract void live();//live 
        
    }
    package javaClassStudy;
    
    /**
     *
     * @author Administrator
     */
    public class Student extends Person  {
    
        public Student(String name, int age) {
            super(name, age);
        }
    
        @Override
        public String getDescription() {
            System.out.println("Name is:"+this.getName());
            return "Name is:" + this.getName();
        }
    
        /**
         *
         */
        @Override
        public void live() {
            System.out.println("I live in a big house!"+this.getName());
          }
        
    }
    /**
     *
     * @author Administrator
     */
    import javaClassStudy.Student;
    import javaClassStudy.Person;
    public class helloWorld {
        public static void main(String[] parm){
              Person p = new Student("yuxg",12);
              p.live();
              System.out.println(p.getDescription() );
        }
    
    }
    View Code
  • 相关阅读:
    [LeetCode 220.] 存在重复元素 III
    C++ 构造函数 & 析构函数
    [LeetCode 891.] 子序列宽度之和【hard】
    [LeetCode 447.] Number of Boomerangs
    HJ93 数组分组
    HJ77 火车进站
    [LeetCode 338.] 比特位计数
    线段树
    大数量问题的一般解决方法
    字典树
  • 原文地址:https://www.cnblogs.com/scown/p/5373254.html
Copyright © 2011-2022 走看看