1.继承的概念:
继承是类与类的一种关系,是一种“is”和“a”的关系
2.继承的好处:
子类拥有父类的所有属性和方法,(不能是private).
3.语法规则:
public class Anima { public int age; public String name; public void eat(){ System.out.println("拥有吃东西的能力"); } } public class Dog extends Anima { } public class Test { public static void main(String[] args) { Dog dog = new Dog(); dog.age = 10; dog.name = "hashiqi"; dog.eat(); } }
原文:https://www.cnblogs.com/zwh820672664/p/10827018.html