java入门第二季–继承–java中的继承

36次阅读

共计 429 个字符,预计需要花费 2 分钟才能阅读完成。

java 中的继承

代码

/javaDemo3/src/com/imooc/Animal.java
package com.imooc;

public class Animal {
public int age;
public String name;
public void eat() {
System.out.println(“eat kill”);
}

}

/javaDemo3/src/com/imooc/Dog.java

package com.imooc;

public class Dog extends Animal {

}

/javaDemo3/src/com/imooc/Initail.java
package com.imooc;

public class Initail {

public static void main(String[] args) {
// TODO Auto-generated method stub
Dog dog = new Dog();
dog.age = 10;
dog.name = “aa”;
dog.eat();
}

}

正文完
 0