zoukankan      html  css  js  c++  java
  • 15、Java中级进阶 面向对象 继承

    1

    123

    2

    使

     private 

    使super()

    super()

    protectedprivate访Java 

    3Java使

    [访] class  extends {
      
    }

    DogAnimalDogAnimalDogAnimal使便

    Animal

    public class Animal {
       
        private Integer age;
       
        public Animal(){
            System.out.println("Animal construct method");
        }

       public Integer getAge() {
           return age;
      }

       public void setAge(Integer age) {
           this.age = age;
      }
       
       public void eat(){
           System.out.println("eat food");
      }
    }

    Dog

    public class Dog extends Animal{
        private String color; //
       
        public Dog(String color){
            this.color = color;
        }
       
        public void run(){
            System.out.println("Dog is running");
        }
       
        @Override
        public void eat(){
           System.out.println("dog eat bone");
        }
       
       public static void main(String[] args) {
                Dog dog = new Dog("");
                dog.eat();
      }
    }


    Animal construct method
    dog eat bone

    new Dogcat

    public class Cat extends Animal{
       
        @Override
        public void eat(){
           super.eat();
           System.out.println("cat eat finsh");
        }
    }

    Cateatcat eat finsheat foodsuper访newsuper使super

    4

    a

    b

    c

     

    5~

    1

    2使extends

    3JAVA

    4

    5

    6protected访7

    8

    9super(...)super


                    

    圈~

     注公众号

  • 相关阅读:
    历史博文汇总
    Golang快速入门:从菜鸟到大佬
    网络1911、1912 DS第4次作业--批改总结
    [机器学习实战-Logistic回归]使用Logistic回归预测各种实例
    [机器学习实战-kNN算法]约会网站问题和手写数字系统实例
    SQL学习笔记(一)之基础语句
    Python学习笔记(九)之面向对象编程(下)
    Python学习笔记(八)之面向对象编程(上)
    Python学习笔记(七)之Python模块
    Python学习笔记(六)之函数式编程
  • 原文地址:https://www.cnblogs.com/naimao/p/13353301.html
Copyright © 2011-2022 走看看