Java 继承

来源:互联网 发布:图后期制作软件 编辑:程序博客网 时间:2024/06/01 09:53
package com.wc.lianxi;


public class test1 {
public static void main(String[] args){
human1 h = new human1();
h.play();
h.sleep();
h.eat();
}
}


class animal1 {
String color;
int age;
String job;

animal1(int x){
System.out.println(x);
}

animal1(String color,int age,String job){
this.color =color;
this.age =age;
this.job =job;
System.out.println("一个 "+age+"岁的"+color+"人"+job+"\t父构造方法");
}

void eat(){
System.out.println("父吃饭");
}

void sleep(){
System.out.println("父睡觉");
}
void play(){
System.out.println("父玩耍");
}
}






class human1 extends animal1{
human1(){
super("黑",18,"worker");
}


void play(){
System.out.println("子玩耍");
}
void eat(){
System.out.println("子吃饭");
}
void sleep(){
System.out.println("子睡觉");
}
 
 
}
原创粉丝点击