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");
        }
      }

    ******************************人因为有理想、梦想而变得伟大,而真正伟大就是不断努力实现理想、梦想*****************************
  • 相关阅读:
    详细,Qt Creator快捷键大全,附快捷键配置方法
    Qt Creator 你必须要掌握的快捷操作
    Linux 终端下颜色的输出
    Qt之JSON生成与解析
    Ubuntu配置和修改IP地址
    USB的VID和PID,以及分类(Class,SubClass,Protocol)
    fatal error: gst/gst.h
    VID、PID查询
    el表达式具体解释
    F
  • 原文地址:https://www.cnblogs.com/cloudLi/p/12893003.html
Copyright © 2011-2022 走看看