zoukankan      html  css  js  c++  java
  • 面向对象--继承

    package com.test;

      public class test_3 {
        public static void main(String[] args) {
          System.out.println();
          dog a =new dog();
          a.setName("test");
          a.eat();
          a.qwe();
        }
      }


      class animal1{
        private int age;
        private String name ;

        public void setAge(int age) {
          this.age = age;
        }
        public void setName(String name) {
          this.name = name;
        }
        public int getAge() {
          return age;
        }
        public String getName() {
          return name;
        }
        public void test() {
          System.out.println(getName()+getAge());
        }
        public void eat() {
          System.out.println(getName()+"是动物");
        }
      }

      class dog extends animal1 {            //extends animal1 为继承 animal1类
        public void qwe() {
          System.out.println(getName()+"是dog");
        }
      }

    ******************************人因为有理想、梦想而变得伟大,而真正伟大就是不断努力实现理想、梦想*****************************
  • 相关阅读:
    如何保证 Redis 缓存与数据库双写一致性?
    如何合理地估算线程池大小?
    不用装工具,一条 Linux 命令就能实现文件上传下载!
    看了 Google 大神 Jeff Dean 的传说,我拜服了~
    div设置水平垂直居中
    "起用"与"启用"
    徇私舞弊
    精选排比金句20例
    一笔画图推
    一笔画
  • 原文地址:https://www.cnblogs.com/cloudLi/p/12893003.html
Copyright © 2011-2022 走看看